A
AnnMarie
<script language="JavaScript" type="text/javascript">
<!--
function validate(theForm)
{
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.name.focus();
event.returnValue=false;
}
if(frmComments.company.value=='' && validity == true)
{
alert('Your company name is required. Please enter the name of your
company!');
validity = false;
frmComments.company.focus();
event.returnValue=false;
}
var pattern1 = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,4})+$/;
if (!pattern1.test(frmComments.email.value) && validity == true)
{
alert("Invalid E-mail Address! Please re-enter.")
frmComments.email.focus();
validity = false;
return false;
}
if(frmComments.zip.value == "" )
return true;
else
{
var pattern2 = /\d{5}/;
if(pattern2.test(frmComments.zip.value))
return true;
else
{
if(!pattern2.test(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.test(frmComments.phone.value))
return true;
else
{
if(!pattern3.test(frmComments.phone.value)&& validity == true)
{
alert("Invalid Phone Number! Must be in form 555-555-5555. Please
re-enter.");
frmComments.phone.focus();
validity = false;
return false;
}
}
}
}
function formSubmit()
{
window.event.returnValue = false;
if ( confirm ( "Are you sure you want to submit?" ) )
window.event.returnValue = true;
}
function formReset()
{
window.event.returnValue = false;
if ( confirm( "Are you sure you want to reset?" ) )
{
frmComments.name.focus();
window.event.returnValue = true;
}
}
// -->
</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"
onclick="formSubmit()">
-----------------------------------------------------------
This is the link to the html page:
http://matrix.csis.pace.edu/~f03-it604-s03/project/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.
<!--
function validate(theForm)
{
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.name.focus();
event.returnValue=false;
}
if(frmComments.company.value=='' && validity == true)
{
alert('Your company name is required. Please enter the name of your
company!');
validity = false;
frmComments.company.focus();
event.returnValue=false;
}
var pattern1 = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,4})+$/;
if (!pattern1.test(frmComments.email.value) && validity == true)
{
alert("Invalid E-mail Address! Please re-enter.")
frmComments.email.focus();
validity = false;
return false;
}
if(frmComments.zip.value == "" )
return true;
else
{
var pattern2 = /\d{5}/;
if(pattern2.test(frmComments.zip.value))
return true;
else
{
if(!pattern2.test(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.test(frmComments.phone.value))
return true;
else
{
if(!pattern3.test(frmComments.phone.value)&& validity == true)
{
alert("Invalid Phone Number! Must be in form 555-555-5555. Please
re-enter.");
frmComments.phone.focus();
validity = false;
return false;
}
}
}
}
function formSubmit()
{
window.event.returnValue = false;
if ( confirm ( "Are you sure you want to submit?" ) )
window.event.returnValue = true;
}
function formReset()
{
window.event.returnValue = false;
if ( confirm( "Are you sure you want to reset?" ) )
{
frmComments.name.focus();
window.event.returnValue = true;
}
}
// -->
</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"
onclick="formSubmit()">
-----------------------------------------------------------
This is the link to the html page:
http://matrix.csis.pace.edu/~f03-it604-s03/project/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.