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 Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Please help --- STUCK! Form field validation

Status
Not open for further replies.

nalbiso

Programmer
Aug 31, 2000
71
US
Hello,

I have a script that checks two radio buttons. If a certain one is checked, the script proceeds to check a text field to make sure that the visitor has inputted data and if not, displays an alert. This part works fine, but after the alert has been displayed, the script immediately committs the record to the database. I want the script to stop and force the visitor to input the required data before committing the record to the database. Here is the code:

<HTML>

<head>
<title>Employee Sign Out Board</title>
</head>

<BODY bgcolor=&quot;#D9D9FF&quot;>
<SCRIPT language=&quot;JavaScript&quot;>
<!--
function InOut() {
if (document.WhereAreYou.elements[1].checked) {
if (document.WhereAreYou.Destination.value==&quot;&quot;) {
alert(&quot;You must input your destination when posting an Out of Office Record!&quot;);
return false;
}
else
return true;
}
}
//-->
</SCRIPT>

<table width=&quot;664&quot; border=&quot;0&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; height=&quot;379&quot;>
<tr bgcolor=&quot;#D9D9FF&quot;>
<td height=&quot;1&quot; valign=&quot;top&quot; colspan=&quot;2&quot; width=&quot;752&quot;>
<p align=&quot;center&quot;>
<img border=&quot;0&quot; src=&quot;images/title2.gif&quot; width=&quot;750&quot; height=&quot;100&quot; align=&quot;left&quot;>

</td>
</tr>
<td width=&quot;84&quot;>
<td width=&quot;666&quot; bgcolor=&quot;#FFFFFF&quot;>
<blockquote>
<h1><font face=&quot;Tahoma&quot;>Edit Office Status:</font></h1>
<p><font face=&quot;Tahoma&quot;><b><i>Note:</i></b>  If you are posting an
&quot;In Office&quot; status, you may click submit to commit the default
values currently posted in this form. If you are posting an &quot;Out of
Office Status&quot;, you must edit the default values for all fields.</font></p>
<FORM Name=&quot;WhereAreYou&quot; method=&quot;POST&quot; action=&quot;EBoard2.asp&quot;>
<p>
<font face=&quot;Tahoma&quot;><b>In Office:</b>
<INPUT TYPE=&quot;radio&quot; name=&quot;rYesNo&quot; value=&quot;In&quot; checked>
<b>Out of Office:</b>
<INPUT TYPE=&quot;radio&quot; name=&quot;rYesNo&quot; value=&quot;Out&quot;>
</font>
</p>
<P>
<font face=&quot;Tahoma&quot;><b>Destination: </b><TEXTAREA rows=&quot;1&quot; cols=&quot;40&quot; NAME=&quot;Destination&quot; TYPE=&quot;text&quot; SIZE=&quot;60&quot; VALUE=&quot;&quot;></textarea>
</font>
<P>
<font face=&quot;Tahoma&quot;><b>Estimated Return Time:</b>
<INPUT TYPE=&quot;text&quot; name=&quot;EstimatedReturnTime&quot; size=&quot;10&quot; value=&quot;00/00/00; 0:00&quot;></font>
<font face=&quot;Tahoma&quot;><b>Date/Time Sign:</b>
<INPUT TYPE=&quot;text&quot; name=&quot;DateTimeSignOut&quot; size=&quot;14&quot; value=&quot;<%=Now()%>&quot;>
</font>
<p><input type=&quot;submit&quot; value=&quot;Submit&quot; name=&quot;B1&quot; onclick=&quot;InOut();&quot;><input type=&quot;reset&quot; value=&quot;Reset&quot; name=&quot;B2&quot;></p>
<input type=&quot;hidden&quot; name=&quot;LastEdit&quot; value=&quot;<%=Request(&quot;LastEdit&quot;)%>&quot;><input type=&quot;hidden&quot; name=&quot;EmpID&quot; value=&quot;<%=Request(&quot;EmpID&quot;)%>&quot;>
</FORM>
</BODY>
</HTML>

Any help is greatly appreciated.
 
Instead of using onClick on your submit button, use onSubmit on your form tag:
Code:
<FORM Name=&quot;WhereAreYou&quot; method=&quot;POST&quot; action=&quot;EBoard2.asp&quot; onSubmit=&quot;return InOut()&quot;>
Tracy Dryden
tracy@bydisn.com

Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard.
 
yea, right, & this would focus user on his typo (error):

function InOut() {
if (document.WhereAreYou.elements[1].checked) {
if (document.WhereAreYou.Destination.value==&quot;&quot;) {
alert(&quot;You must input your destination when posting an Out of Office Record!&quot;);
document.WhereAreYou.Destination.focus();
return false;
}
else
return true;
}
}

Victor
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top