A
AnnMarie
My JavaScript Form Validation doesn't work at all in Netscape, but it
works fine in IE.
I made some of the suggested changes which enabled it to work in IE.
I couldn't make all the changes because then it didn't work in IE.
How can I enable this javascipt form validation to work in Netscape?
When I use netscape, none of the alert boxes appear. It submits the
form without validating anything.
In IE, I get all the alert boxes and everything is validated.
Thanks.
The relevant code is:
<script language="JavaScript" type="text/javascript">
<!--
function validate(theForm)
{
var validity = true; // assume valid
// If user doesn't enter required name, alert them
if(frmComments.name.value == '' && validity == true)
{
alert('Your full name is required.\nPlease enter your full
name!');
validity = false;
frmComments.name.focus();
return false;
}
// If user doesn't enter required company, alert them
if(frmComments.company.value == '' && validity == true)
{
alert('Your company name is required.\n' +
'Please enter the name of your company!');
validity = false;
frmComments.company.focus();
return false;
}
// If user doesn't enter the correct email format alert them
// Email is not required
var pattern1 = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,4})+$/;
if (!pattern1.test(frmComments.email.value) && validity == true)
{
alert('Invalid E-mail Address!\n' +
'Please re-enter.')
frmComments.email.focus();
validity = false;
return false;
}
// If user doesn't enter the correct zip code format alert them
// Zip Code is not required
if(!frmComments.zip.value == '' )
{
var pattern2 = /^\d{5}$/ ;
if(!pattern2.test(frmComments.zip.value))
{
if(!pattern2.test(frmComments.zip.value) && validity ==
true)
{
alert('Invalid Zip Code!\nMust be in form 12345.\n' +
'Please re-enter.');
frmComments.zip.focus();
validity = false;
return false;
}
}
}
// If user doesn't enter the correct phone number format alert
them
// Phone Number is not required
if(!frmComments.phone.value == '')
{
var pattern3 = /\d{3}\-\d{3}\-\d{4}/;
if(!pattern3.test(frmComments.phone.value))
{
if(!pattern3.test(frmComments.phone.value)&& validity ==
true)
{
alert('Invalid Phone Number!\nMust be in form
555-555-5555.\n' +
'Please re-enter.');
frmComments.phone.focus();
validity = false;
return false;
}
}
// If data entered is valid, confirm submission
if(validity == true)
return formSubmit();
}
// Confirm submission
function formSubmit()
{
return ( confirm('Are you sure you want to submit?'));
frmComments.name.focus();
}
// Confirm clearing of fields
function formReset()
{
return ( confirm( "Are you sure you want to reset?" ) )
frmComments.name.focus();
}
// -->
</script>
<form id="frmComments"
action="http://matrix.csis.pace.edu/~f03-it604-s03/cgi-bin/comments.pl"
method="post" onSubmit="return validate(this);" onReset="return
formReset(this)">
<input type="submit" align="right" value="Submit" name="submit"
onchange="frmComments.name.focus();"
onblur="frmComments.name.focus();">
<input type="reset" align="right" value="Clear" name="reset">
The link to this page is:
http://matrix.csis.pace.edu/~f03-it604-s03/project/comments.html
works fine in IE.
I made some of the suggested changes which enabled it to work in IE.
I couldn't make all the changes because then it didn't work in IE.
How can I enable this javascipt form validation to work in Netscape?
When I use netscape, none of the alert boxes appear. It submits the
form without validating anything.
In IE, I get all the alert boxes and everything is validated.
Thanks.
The relevant code is:
<script language="JavaScript" type="text/javascript">
<!--
function validate(theForm)
{
var validity = true; // assume valid
// If user doesn't enter required name, alert them
if(frmComments.name.value == '' && validity == true)
{
alert('Your full name is required.\nPlease enter your full
name!');
validity = false;
frmComments.name.focus();
return false;
}
// If user doesn't enter required company, alert them
if(frmComments.company.value == '' && validity == true)
{
alert('Your company name is required.\n' +
'Please enter the name of your company!');
validity = false;
frmComments.company.focus();
return false;
}
// If user doesn't enter the correct email format alert them
// Email is not required
var pattern1 = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,4})+$/;
if (!pattern1.test(frmComments.email.value) && validity == true)
{
alert('Invalid E-mail Address!\n' +
'Please re-enter.')
frmComments.email.focus();
validity = false;
return false;
}
// If user doesn't enter the correct zip code format alert them
// Zip Code is not required
if(!frmComments.zip.value == '' )
{
var pattern2 = /^\d{5}$/ ;
if(!pattern2.test(frmComments.zip.value))
{
if(!pattern2.test(frmComments.zip.value) && validity ==
true)
{
alert('Invalid Zip Code!\nMust be in form 12345.\n' +
'Please re-enter.');
frmComments.zip.focus();
validity = false;
return false;
}
}
}
// If user doesn't enter the correct phone number format alert
them
// Phone Number is not required
if(!frmComments.phone.value == '')
{
var pattern3 = /\d{3}\-\d{3}\-\d{4}/;
if(!pattern3.test(frmComments.phone.value))
{
if(!pattern3.test(frmComments.phone.value)&& validity ==
true)
{
alert('Invalid Phone Number!\nMust be in form
555-555-5555.\n' +
'Please re-enter.');
frmComments.phone.focus();
validity = false;
return false;
}
}
// If data entered is valid, confirm submission
if(validity == true)
return formSubmit();
}
// Confirm submission
function formSubmit()
{
return ( confirm('Are you sure you want to submit?'));
frmComments.name.focus();
}
// Confirm clearing of fields
function formReset()
{
return ( confirm( "Are you sure you want to reset?" ) )
frmComments.name.focus();
}
// -->
</script>
<form id="frmComments"
action="http://matrix.csis.pace.edu/~f03-it604-s03/cgi-bin/comments.pl"
method="post" onSubmit="return validate(this);" onReset="return
formReset(this)">
<input type="submit" align="right" value="Submit" name="submit"
onchange="frmComments.name.focus();"
onblur="frmComments.name.focus();">
<input type="reset" align="right" value="Clear" name="reset">
The link to this page is:
http://matrix.csis.pace.edu/~f03-it604-s03/project/comments.html