Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem with Javascript Validation

Status
Not open for further replies.

kaycee79

Technical User
Jan 10, 2004
82
GB


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 =&quot;clock.inc&quot;-->


<SCRIPT language=&quot;JavaScript&quot;>
<!--
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=&quot;The following fields appear to be invalid:&quot;;
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!=&quot;SUBMIT&quot;)&&(theType!=&quot;RESET&quot;)) {
// check if the field is the Email address and validate
if((theName==&quot;txtEmailAddress&quot;)&&(!formValidateEmail(theValue))) {
msg+=&quot;\n* &quot;+theName.substring(3,theName.length);
blank=true;
}
// check the other fields but ignore txtAddress2
if((theName!=&quot;txtAddress2&quot;)&&(theValue==&quot;&quot;)) {
msg+=&quot;\n* &quot;+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 (&quot;Your passwords do not match - please reenter&quot;);
return false;
} else return true;
} else return false;
}
//-->
</SCRIPT>
<div id=&quot;content&quot;>
<input type=&quot;button&quot; onClick=&quot;document.all.content.style.zoom=(document.all.content.style.zoom==1?2:1);&quot; value=&quot;Change Font Size&quot;>

<title>Registration Form</title>
</head>
<body style=&quot;font-family: arial&quot;>




<body onload=&quot;StartClock()&quot; onunload=&quot;KillClock()&quot;>
<form name=&quot;theClock&quot; action=&quot;adduser1.asp&quot; METHOD=&quot;post&quot; onSubmit=&quot;return VerifyData();&quot;>
<input type=&quot;text&quot; name=&quot;theTime&quot; size=6><% Response.Write Date %><br>



<H1 align=&quot;center&quot;><u>Registration Form</u></H1>

Title: <SELECT NAME=&quot;txtTitle&quot;>
<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=&quot;text&quot; name=&quot;txtFirstName&quot;><br>
Surname: <input type=&quot;text&quot; name= &quot;txtSurname&quot;><br>
Address1: <input type=&quot;text&quot; name=&quot;txtAddress1&quot;><br>
Address2: <input type=&quot;text&quot; name=&quot;txtAddress2&quot;><br>
Town: <input type=&quot;text&quot; name=&quot;txtTown&quot;><br>
County: <input type=&quot;text&quot; name=&quot;txtCounty&quot;><br>
Post Code: <input type=&quot;text&quot; name=&quot;txtPostCode&quot;><br>
Telephone Number: <input type=&quot;text&quot; name=&quot;txtTelephoneNo&quot;><br>
Email Address: <input type=&quot;text&quot; name=&quot;txtEmailAddress&quot;><br>
Username: <input type=&quot;text&quot; name=&quot;txtUsername&quot;><br>
Password: <input type=&quot;password&quot; name=&quot;txtPassword&quot;><br>
Verify Password: <input type=&quot;password&quot; name=&quot;txtVerifyPassword&quot;><br>
Secret Question: <input type=&quot;text&quot; name=&quot;txtSecretQuestion&quot;><BR>

<INPUT TYPE=&quot;SUBMIT&quot; VALUE=&quot;Submit&quot;> <INPUT TYPE=&quot;RESET&quot; VALUE=&quot;Clear&quot;>
</form>
<p>
<a href=&quot;home.asp&quot;>HOME</a>
</div>
</body>
</html>
 


none of these select options have values

try this

<OPTION value=&quot;mr&quot;>Mr</OPTION>
<OPTION value=&quot;mrs&quot;>Mrs</OPTION>
<OPTION value=&quot;miss&quot;>Miss</OPTION>
<OPTION value=&quot;ms&quot;>Ms</OPTION>
<OPTION value=&quot;master&quot;>Master</OPTION>
<OPTION value=&quot;doctor&quot;>Doctor</OPTION>
<OPTION value=&quot;lord&quot;>Lord</OPTION>
<OPTION value=&quot;sir&quot;>Sir</OPTION>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top