I currently have a javascript validation on my form where all the fields must be filled in or there is an error message that appears. I have a list box for one of my fields, and when I select a value from my list box and try to submit it, I am getting the error message telling me that I have not filled in the ‘title’ field.
Can anyone help me with this problem
Thanks in advance
This is the code I am using;
<!--#include file ="clock.inc"-->
<SCRIPT language="JavaScript">
<!--
function formValidateEmail(email) {
var regex = /^[a-zA-Z0-9._-]+@([a-zA-Z0-9.-]+\.)+[a-zA-Z0-9.-]{2,4}$/;
return regex.test(email);
}
function VerifyFields() {
var msg="The following fields appear to be invalid:";
var blank=false;
for(var x=0;x<document.forms[0].length;x++) {
theObj=document.forms[0].elements[x];
theType=theObj.type;
theName=theObj.name;
theValue=theObj.value;
if((theType!="SUBMIT"
// check if the field is the Email address and validate
if((theName=="txtEmailAddress"
msg+="\n* "+theName.substring(3,theName.length);
blank=true;
}
// check the other fields but ignore txtAddress2
if((theName!="txtAddress2"
msg+="\n* "+theName.substring(3,theName.length);
blank=true;
}
}
}
if(blank) {
alert(msg);
return false;
}
return true;
}
function VerifyData() {
if (VerifyFields()) {
if (document.frmUser.txtPassword.value != document.frmUser.txtVerifyPassword.value) {
alert ("Your passwords do not match - please reenter"
return false;
} else return true;
} else return false;
}
//-->
</SCRIPT>
<div id="content">
<input type="button" onClick="document.all.content.style.zoom=(document.all.content.style.zoom==1?2:1);" value="Change Font Size">
<title>Registration Form</title>
</head>
<body style="font-family: arial">
<body onload="StartClock()" onunload="KillClock()">
<form name="theClock" action="adduser1.asp" METHOD="post" onSubmit="return VerifyData();">
<input type="text" name="theTime" size=6><% Response.Write Date %><br>
<H1 align="center"><u>Registration Form</u></H1>
Title: <SELECT NAME="txtTitle">
<OPTION>Mr</OPTION>
<OPTION>Mrs</OPTION>
<OPTION>Miss</OPTION>
<OPTION>Ms</OPTION>
<OPTION>Master</OPTION>
<OPTION>Doctor</OPTION>
<OPTION>Lord</OPTION>
<OPTION>Sir</OPTION>
</SELECT><BR>
First Name: <input type="text" name="txtFirstName"><br>
Surname: <input type="text" name= "txtSurname"><br>
Address1: <input type="text" name="txtAddress1"><br>
Address2: <input type="text" name="txtAddress2"><br>
Town: <input type="text" name="txtTown"><br>
County: <input type="text" name="txtCounty"><br>
Post Code: <input type="text" name="txtPostCode"><br>
Telephone Number: <input type="text" name="txtTelephoneNo"><br>
Email Address: <input type="text" name="txtEmailAddress"><br>
Username: <input type="text" name="txtUsername"><br>
Password: <input type="password" name="txtPassword"><br>
Verify Password: <input type="password" name="txtVerifyPassword"><br>
Secret Question: <input type="text" name="txtSecretQuestion"><BR>
<INPUT TYPE="SUBMIT" VALUE="Submit"> <INPUT TYPE="RESET" VALUE="Clear">
</form>
<p>
<a href="home.asp">HOME</a>
</div>
</body>
</html>