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

Help Form Validation

Status
Not open for further replies.

dfc41

Technical User
Nov 18, 2002
4
0
0
US
New to javascript, so bare with me. Having problems with required fields in my form.
Here is my code:

<SCRIPT LANGUAGE="JavaScript">
<!-- Begin
function verify() {
var themessage = "You are required to complete the following fields: ";
if (document.forms.Name_required.value=="") {
themessage = themessage + " - Name";
}
if (document.forms.Phone_required.value=="") {
themessage = themessage + " - Phone Number";
}
if (document.forms.Email_required.value=="") {
themessage = themessage + " - E-mail";
}
//alert if fields are empty and cancel form submit
if (themessage == "You are required to complete the following fields: ") {
document.form.submit();
}
else {
alert(themessage);
return false;}
}
// End -->
</script>

<form action=" method="post" onsubmit="return verify();">

<tr>
<th align="right" width="175" height="22"><font size="2">Name
<span style="font-weight: 400"><i>(required)</i></span>: </font></th>
<td width="246" height="22">
<input type="text" name="Name__required_" size="30" /><font size="2">
</font></td>
</tr>
<tr>
<th align="right" width="175" height="22"><font size="2">Phone
<span style="font-weight: 400"><i>(required)</i></span>: </font></th>
<td width="246" height="22">
<input type="text" name="Phone__required_" size="30" /><font size="2">
</font></td>
</tr>
<tr>
<th align="right" width="175" height="22"><font size="2">Email
<span style="font-weight: 400"><i>(required)</i></span>: </font></th>
<td width="246" height="22">
<input type="text" name="Email__required_" size="30" /><font size="2">
</font></td>
</tr>
<input type="submit" value="Submit Form" name="Form_Submit" />
<input type="hidden" value="104" name="_vDeckformid" />
</form>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top