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>
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>