spanish_steps
06-07-2003, 08:49 PM
Hola,
Before i submit a form, i would like to check if all the fields are filled and also i would like to check if my e-mail is entered in a proper format.
It checks for the name and the text but it does'nt check for the e-mail.
Could somebody please tell me where i'm going wrong.
Many thanks
<html>
<head>
<meta http-equiv="Content-Language" content="en-us">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<meta name="GENERATOR" content="Microsoft FrontPage 4.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<title>Contact Page</title>
<SCRIPT LANGUAGE="JavaScript">
function verify() {
var themessage = "You are required to complete the following fields: ";
if (document.form.name.value=="") {
themessage = themessage + " - Your Name";
}
if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(document.form.email.value)){
themessage = themessage + " - Your E-mail";
}
if (document.form.description.value=="") {
themessage = themessage + " - Your Description";
}
//alert if fields are empty and cancel form submit
if (themessage == "You are required to complete the following fields: ") {
document.form.submit();
}
else {
alert(themessage);
return false;
}
}
</script>
</head>
<body bgcolor="#FFFFCC">
<form name=form method="post" action="contactform.html">
Fields with '<font color="#ff0000">*</font>' are mandatory.
<table border="1" width="100%">
<tr>
<td width="50%">Your Name <font color="#FF0000">*</td>
<td width="50%">
<p><input type="text" name="name" size="20"></p>
</td>
</tr>
<tr>
<td width="50%">Your E-mail <font color="#FF0000">*</td>
<td width="50%"><input type="text" name="email" size="20"></td>
</tr>
<tr>
<td width="50%">Your Description <font color="#FF0000">*</td>
<td width="50%">
<p><textarea rows="7" name="description" cols="60"></textarea></p>
</td>
</tr>
</table>
<table border="1" width="100%">
<tr>
<td width="100%"><input type=button value="Submit" onclick="verify();"></td>
</tr>
</table>
</form>
</body>
</html>
Before i submit a form, i would like to check if all the fields are filled and also i would like to check if my e-mail is entered in a proper format.
It checks for the name and the text but it does'nt check for the e-mail.
Could somebody please tell me where i'm going wrong.
Many thanks
<html>
<head>
<meta http-equiv="Content-Language" content="en-us">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<meta name="GENERATOR" content="Microsoft FrontPage 4.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<title>Contact Page</title>
<SCRIPT LANGUAGE="JavaScript">
function verify() {
var themessage = "You are required to complete the following fields: ";
if (document.form.name.value=="") {
themessage = themessage + " - Your Name";
}
if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(document.form.email.value)){
themessage = themessage + " - Your E-mail";
}
if (document.form.description.value=="") {
themessage = themessage + " - Your Description";
}
//alert if fields are empty and cancel form submit
if (themessage == "You are required to complete the following fields: ") {
document.form.submit();
}
else {
alert(themessage);
return false;
}
}
</script>
</head>
<body bgcolor="#FFFFCC">
<form name=form method="post" action="contactform.html">
Fields with '<font color="#ff0000">*</font>' are mandatory.
<table border="1" width="100%">
<tr>
<td width="50%">Your Name <font color="#FF0000">*</td>
<td width="50%">
<p><input type="text" name="name" size="20"></p>
</td>
</tr>
<tr>
<td width="50%">Your E-mail <font color="#FF0000">*</td>
<td width="50%"><input type="text" name="email" size="20"></td>
</tr>
<tr>
<td width="50%">Your Description <font color="#FF0000">*</td>
<td width="50%">
<p><textarea rows="7" name="description" cols="60"></textarea></p>
</td>
</tr>
</table>
<table border="1" width="100%">
<tr>
<td width="100%"><input type=button value="Submit" onclick="verify();"></td>
</tr>
</table>
</form>
</body>
</html>