I am newbie to javascript and am trying to figure out a form validation problem. I have created the following function:
<SCRIPT LANGUAGE="javascript">
function checkform()
{
if(document.info.first.value == '')
{
alert('Please fill out the First Name field to continue');
}
if(document.info.last.value == '')
{
alert('Please fill out the Last Name field to continue');
}
if(document.info.address.value == '')
{
alert('Please fill out the Address field to continue');
}
if(document.info.city.value == '')
{
alert('Please fill out the City field to continue');
}
if(document.info.state.value == '--Make a Selection--')
{
alert('Please choose a State from the dropdown box to continue');
}
if(document.info.zip.value == '')
{
alert('Please fill out the 5-digit zip code field to continue');
}
}
</SCRIPT>
The FORM tag is as follows:
<FORM NAME="info" ACTION="order.pl" METHOD="post">
The order.pl prints the information entered on another screen.
I am using the following INPUT type with an onclick variable to call the function:
<INPUT type="submit" onclick="return checkform()" VALUE="Buy Now">
When the function is called it will pop the proper alert but instead of remaining on the page to allow the user to input the proper data it continues on and passes the incomplete data to the order.pl program.
Example: Note the imcomplete Last Name field that was passed.
First Name: Steve
Last Name:
Address: 123 Main
City: Nowhere
State: KS
Zip: 12345
Any suggestions appreciated. Thanks.
Steve
<SCRIPT LANGUAGE="javascript">
function checkform()
{
if(document.info.first.value == '')
{
alert('Please fill out the First Name field to continue');
}
if(document.info.last.value == '')
{
alert('Please fill out the Last Name field to continue');
}
if(document.info.address.value == '')
{
alert('Please fill out the Address field to continue');
}
if(document.info.city.value == '')
{
alert('Please fill out the City field to continue');
}
if(document.info.state.value == '--Make a Selection--')
{
alert('Please choose a State from the dropdown box to continue');
}
if(document.info.zip.value == '')
{
alert('Please fill out the 5-digit zip code field to continue');
}
}
</SCRIPT>
The FORM tag is as follows:
<FORM NAME="info" ACTION="order.pl" METHOD="post">
The order.pl prints the information entered on another screen.
I am using the following INPUT type with an onclick variable to call the function:
<INPUT type="submit" onclick="return checkform()" VALUE="Buy Now">
When the function is called it will pop the proper alert but instead of remaining on the page to allow the user to input the proper data it continues on and passes the incomplete data to the order.pl program.
Example: Note the imcomplete Last Name field that was passed.
First Name: Steve
Last Name:
Address: 123 Main
City: Nowhere
State: KS
Zip: 12345
Any suggestions appreciated. Thanks.
Steve