Jump to content
Larry Ullman's Book Forums

'Return False' Problem And A Solution


Recommended Posts

My form validation refused to stop the submit event after acknowledging ‘alert’. This is the conclusion of the validation script:

if (problem == 'No'){

return true;

}else{

alert(alerts);

return false;

}

After much trial and error, the following script does stop the 'submit' event:

event.returnValue=false;

 

This tip might help others. I don't recall seeing this solution in the book. I have no idea why it is needed but it is required with my script. Maybe there is some error or 'event bubbling' but I cannot find the error. My form is complex with several event listeners.

 

This is a great book explaining javascript and the best approach to using javascript. Thank you Larry.

Link to comment
Share on other sites

Thanks for the nice words on the book. It is appreciated. What you describe here is explained on page 298. Keep in mind that it only works on older version of IE 8 when using attachEvent() to create the event listener. It will not work on IE9 and later, or on any other browser.

Link to comment
Share on other sites

Thank you for such fast comments. I really appreciate you pointing out that section in your book. I missed the text & now see it is also well indexed!

 

One note on e.returnValue=false, This did not work with Firefox 12.0. However it works with IE 9.0, Opera 11.62, Safari 5.5.5, Chrome 18.0.1025.168 on my computer.

Link to comment
Share on other sites

That's because non-IE browsers have (over time, begrudgingly) been built to understand various IE methods and behaviors in order to help developers with inconsistencies across browsers.

Still, like Larry said, it's best to assume that there's the IE way of doing things and the right way (which all other browsers do), and then design your JS to handle both.

Link to comment
Share on other sites

 Share

×
×
  • Create New...