Javascript Return False Not Stopping Form Submission
We've got some code like this that has been working for some time. It's for a button that submits an html form, unless a nearby textbox is empty. I've taken this snippet directly
Solution 1:
You mentioned jQuery, jQuery can interfere with your form if it is doing anything through its submit()
handler. Check to see if jQuery.submit()
is bound to your form.
Usually when doing pure javascript it is not enough to return false. Depending on what you want to accomplish you might want to look at preventDefault
or stopPropagation
When working with Internet Explorer be aware that the event object is not passed to the function but can be found in window.event
instead.
Update
Internet explorer might want you to use event.returnValue = false;
instead. In your case that would be window.event.returnValue = false;
when targeting IE.
Good luck
Solution 2:
Javascript protocol links have to be one line, ie. no new lines.
onclick="javascript:var obj = document.all ? document.all["aTextInputFormFieldId"] :document.getElementById("aTextInputFormFieldId"); if(obj.value.length == 0){alert('It is 0!'); return false;};"
Post a Comment for "Javascript Return False Not Stopping Form Submission"