allinc666
asked on
JavaScript validation with an onChange in a form.
Hi I have a quick question. How do I make a Javascript code that checks to see if 9 numbers are entered in to a text field then takes you to another page while passing the 9 numbers into a form?
<html>
<head>
<script language="javascript">
function formSubmit(sVal)
{
var sError = "";
if(sVal.length!=9 || isNaN(sVal)) sError+="- Please enter 9 digits";
if(sError!="") alert("The following errors occured: \n"+sError);
return sError=="";
}
</script>
</head>
<body>
<form action="nextpage.asp">
<input type="text" onChange="if(formSubmit(th is.value)) this.form.submit();">
</form>
</body>
</html>
or with the form being:
<form action="nextpage.asp" onSubmit="return formSubmit(this.txt1.value )">
<input type="text" name="txt1"><br>
<input type="submit">
</form>
<head>
<script language="javascript">
function formSubmit(sVal)
{
var sError = "";
if(sVal.length!=9 || isNaN(sVal)) sError+="- Please enter 9 digits";
if(sError!="") alert("The following errors occured: \n"+sError);
return sError=="";
}
</script>
</head>
<body>
<form action="nextpage.asp">
<input type="text" onChange="if(formSubmit(th
</form>
</body>
</html>
or with the form being:
<form action="nextpage.asp" onSubmit="return formSubmit(this.txt1.value
<input type="text" name="txt1"><br>
<input type="submit">
</form>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
No comment has been added lately, so it's time to clean up this TA.
I will leave the following recommendation for this question in the Cleanup topic area:
Split: cubrovic {http:#8759027} & CJ_S {http:#8759133}
Please leave any comments here within the next seven days.
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
jAy
EE Cleanup Volunteer
I will leave the following recommendation for this question in the Cleanup topic area:
Split: cubrovic {http:#8759027} & CJ_S {http:#8759133}
Please leave any comments here within the next seven days.
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
jAy
EE Cleanup Volunteer
{
var sError = "";
if(sVal.length!=9 || isNaN(sVal)) sError+="- Please enter 9 digits";
if(sError!="") alert("The following errors occured: \n"+sError);
return sError=="";
}
and call it using
<form>
<input type="text" onChange="if(formSubmit(th
</form>