Jump to content
Larry Ullman's Book Forums
Sign in to follow this  
martinb

'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.

Share this post


Link to post
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.

Share this post


Link to post
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.

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...