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

easy Javascript textbox input validation

Status
Not open for further replies.

techskool

Technical User
Jun 20, 2002
151
GB
Hi Guys

I have to validate for form input.

I have a form with 4 textboxes, and i need to check onSubmit that at least one of the four fields has been filled out.

How do i do this please?

Many Thanks

Dave
 
This is the basics of how to do it. You can expand it from here:

In the <head> section:

<script language="JavaScript" type="text/javascript">

function validateForm()
{
val1 = document.frmName.text1.value;
val2 = document.frmName.text2.value;
val3 = document.frmName.text3.value;
val4 = document.frmName.text4.value;
if (val1.length == 0 && val2.length == 0 && val3.length == 0 && val4.length == 0)
{
alert("Enter your error message here.");
document.frmName.text1.focus();
return false;
}
}

</script>

In the <body> section:

<form action="okayPage.html" method="post" name="frmName" onSubmit="return validateForm();">
<input type="text" width="20" name="text1"><br>
<input type="text" width="20" name="text2"><br>
<input type="text" width="20" name="text3"><br>
<input type="text" width="20" name="text4"><br>
<input type="submit" value="submit">
</form>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top