<script language="JavaS cript" type="text/javascript">
<!--
function validate(theFor m)
{
var validity = true; // assume valid
if(frmComments. name.value=='' && validity == true)
{
alert('Your full name is required. Please enter your full name!');
validity = false;
frmComments.nam e.focus();
event.returnVal ue=false;
}
if(frmComments. company.value== '' && validity == true)
{
alert('Your company name is required. Please enter the name of your
company!');
validity = false;
frmComments.com pany.focus();
event.returnVal ue=false;
}
var pattern1 = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,4 })+$/;
if (!pattern1.test (frmComments.em ail.value) && validity == true)
{
alert("Invalid E-mail Address! Please re-enter.")
frmComments.ema il.focus();
validity = false;
return false;
}
if(frmComments. zip.value == "" )
return true;
else
{
var pattern2 = /\d{5}/;
if(pattern2.tes t(frmComments.z ip.value))
return true;
else
{
if(!pattern2.te st(frmComments. zip.value) && validity == true)
{
alert("Invalid Zip Code! Must be in form 12345. Please re-enter.");
frmComments.zip .focus();
validity = false;
return false;
}
}
}
if(frmComments. phone.value == "")
return true;
else
{
var pattern3 = /\d{3}\-\d{3}\-\d{4}/;
if(pattern3.tes t(frmComments.p hone.value))
return true;
else
{
if(!pattern3.te st(frmComments. phone.value)&& validity == true)
{
alert("Invalid Phone Number! Must be in form 555-555-5555. Please
re-enter.");
frmComments.pho ne.focus();
validity = false;
return false;
}
}
}
}
function formSubmit()
{
window.event.re turnValue = false;
if ( confirm ( "Are you sure you want to submit?" ) )
window.event.re turnValue = true;
}
function formReset()
{
window.event.re turnValue = false;
if ( confirm( "Are you sure you want to reset?" ) )
{
frmComments.nam e.focus();
window.event.re turnValue = true;
}
}
// -->
</script>
<form id="frmComments "
action="http://matrix.csis.pac e.edu/~f03-it604-s03/cgi-bin/comments.pl"
method="post" onSubmit="retur n validate(this); " onReset="return
formReset(this) ">
<input type="submit" align="right" value="Submit" name="submit"
onclick="formSu bmit()">
-----------------------------------------------------------
This is the link to the html page:
http://matrix.csis.pace.edu/~f03-it6.../comments.html
I tried to make the code easier to read by manually formatting it by
removeing the indents and line breaks. I don't know the technique you
suggested of formatting it with a certain number of columns. Please
let me know how to do that.
I am new to this group and may do things incorrectly until learn.
I don't know if you remember my problem of:
My phone validation doesn't work within my validate function. It works
alone, but not within this function like the other validations do.
Phone is not required, but if the user enters a phone number it must
be in the form of 555-555-5555.
Also, my submit confirmation dialog box comes up first and
continuously. I want it to appear last and once before final valid
submission.
Please let me know of a correct and better way of validating these
required fields: name, company, email, and validating phone for
correct format if user fills in phone number.
Thanks for your help.