PDA

View Full Version : Field validation w/js and jquery



sme
03-08-2012, 09:48 PM
Hello!

I am currently a student at a local university studying C# and .NET. I do have a personal project however that is making my life crazy!

In adding a simple validated email form to a personal website I am adding text for the user to enter for validation of the form however it is not working correctly. For some reason, on clicking the submit button a validation error prints to screen even when the correct code is entered.

I appreciate any help you can offer. I hope the information I've supplied is sufficient.

I am using the scripts and libraries listed in the code below:




Script includes:
<script type="text/javascript" src="http://code.jquery.com/jquery-latest.js"></script>
<script type="text/javascript" src="/jquery.validate.js"></script>
<script type="text/javascript" src="/inProgress/javascript/formValidation.js"></script>


<p class="labelCode">Please enter code:</p>
<p id="codeVerify" name="codeVerify" value="xM14z">xM14z</p>
<input type="code" name="code" id="code" size="15" class="required">

code for formvalidation.js file:

$(document).ready(function() {
$('#entry').validate({
rules: {

name: {
required: true,
rangelength: [3,35]
},
email: {
required: true,
email: true},
code: {
equalTo: '#codeVerify'
}
},

messages: {

name: {required: "Please enter your name."},
email: {required: "E-mail addy please.", email: "Your email must be valid!"},
code: {equalTo: "Please enter the correct code!"}
}



}); // end of validate()
});

jscheuer1
03-09-2012, 06:33 AM
You can't use a p like that. You can do it like so using a hidden input:


<p class="labelCode">Please enter code:</p>
<p><input type="hidden" id="codeVerify" name="codeVerify" value="xM14z">xM14z</p>
<input type="code" name="code" id="code" size="15" class="required">

sme
03-12-2012, 05:04 PM
Thank you ~ works perfectly!