validation - JavaScript return false not stopping form submission -


we've got code has been working time. it's button submits html form, unless nearby textbox empty. i've taken snippet directly our code; i've changed contents of fields, haven't deleted anything.

<input      type="image"      name="inputname"         id="inputid"      src="someimage"      alt="alttext"     onclick="         javascript:var obj = document.all ? document.all[&quot;atextinputformfieldid&quot;] :          document.getelementbyid(&quot;atextinputformfieldid&quot;);          if(obj.value.length == 0)         {             alert('it 0!');             return false;         };"      style="somestyle" /> 

(the original code on 1 line, linebreaks have been added here clarity).

it seems work in firefox. in ie, fails in way can't understand: if input field (atextinputformfieldid) empty, puts alert, submits form anyway after user clicks okay button on alert.

when did view source on entire page, , copied locally, seems work perfectly; either submits form, or puts alert, , refuses submit.

my best current (but still lousy) theory 1 of included javascript libraries doing funny, explain why failed on real site, fails when copy locally (since didn't grab various libraries it's importing.) makes logical sense, , i'll check out grabbing libraries too, i'm having hard time imagining these libraries doing mess (or why)...they're normal utility libraries jquery, utility functions, etc.

so have theory happening here?

you mentioned jquery, jquery can interfere form if doing through submit() handler. check see if jquery.submit() bound form.

usually when doing pure javascript not enough return false. depending on want accomplish might want @ preventdefault or stoppropagation

when working internet explorer aware event object not passed function can found in window.event instead.

update internet explorer might want use event.returnvalue = false; instead. in case window.event.returnvalue = false; when targeting ie.

good luck


Comments

Popular posts from this blog

python - Scipy curvefit RuntimeError:Optimal parameters not found: Number of calls to function has reached maxfev = 1000 -

c# - How to add a new treeview at the selected node? -

java - netbeans "Please wait - classpath scanning in progress..." -