Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

aborting sending incomplete form 1

Status
Not open for further replies.

olivia

Programmer
Apr 10, 2000
8
US
Hi, <br>Anyone know how to abort a post operation if the form data is incomplete? do you not specify the action in the form tag but put it in the script to be sent if it passes the validation?? Any ideas gratefully received. thanks!!<br><br>this is what I'm thinking but it doesn't work. <br><FONT FACE=monospace><br>function checkcurrent() {<br> if (form.Patient_ID.value == &quot;&quot; ¦¦ form.Hospital.value == &quot;&quot;) {<br> alert(&quot;Please enter both the patient ID and the hospital&quot;)<br>}else{ <br>(form.action == &quot;send to cgi&quot;)<br> }<br> }<br></font>
 
In your &lt;form&gt; tag, add an onSubmit handler:<br><br>&lt;form action='mypage' method='post' onSubmit='return checkcurrent()'&gt;<br><br>if the checkcurrent() function returns true, the submit will happen.&nbsp;&nbsp;If it returns false, the submit is cancelled. <br><br>Note that 'return' is required before the function name, or the cancel won't work. <p>nick bulka<br><a href=mailto:nick@bulka.com>nick@bulka.com</a><br><a href= > </a><br>
 
Thanks, I tried doing this taking out the {else} statement but it still submits after the dialogue box pops up. Now it looks like this. Am I missing something?!<br><br><FONT FACE=monospace>function checkcurrent() {<br>if (form.Patient_ID.value == &quot;&quot; ¦¦ form.Hospital.value == &quot;&quot;) { <br>alert(&quot;Please enter both the patient ID and the hospital&quot;)<br>&nbsp;}<br>}<br><br>&lt;form Action=&quot;gotoserver&quot; onSubmit=&quot;return checkcurrent()&quot; METHOD=&quot;post&quot;&gt;</font>
 
change the function to this:<br><br>function checkcurrent(){<br>if (form.Patient_ID.value==''¦¦form.Hospital.value==''){<br>alert('Please enter both the patient ID and the hospital&quot;);<br>return true;<br>} else {return false;}<br>}<br><br> <p>theEclipse<br><a href=mailto:eclipse_web@hotmail.com>eclipse_web@hotmail.com</a><br><a href=robacarp.webjump.com>robacarp.webjump.com</a><br>**-Trying to build a documentation of a Javascript DOM, crossbrowser, of course. E-mail me if you know of any little known events and/or methods, etc.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top