The below jquery script iam using. But this is working in both firefox and chrome but not in IE.
<script type="text/javascript">
$.validator.setDefaults({
submitHandler: function() {
//alert("submitted!");
debug: false;
form.submit();
}
});;
</script>
<script type="text/javascript">
$(document).ready(function() {
$.validator.addMethod("mobilecheck", function(value, element) {
return this.optional(element) || /^[0-9]+$/i.test(value);
}, "mobile number must contain only numbers");
$.validator.addMethod("namecheck", function(value, element) {
return this.optional(element) || /^[a-z\s]+$/i.test(value);
}, "User Name must contain only letters");
$("#myform").validate({
rules: {
fullname:{ required : true , namecheck :true},
mobile:{ required : true, mobilecheck :true },
city: { required : true},
locality: { required : true},
email: {
required: true,
email: true
},
jobcity: { required : true} ,
hometown: { required : true} ,
},
messages: {
fullname:{
required: "Please enter your fullname" ,
namecheck: " Full Name must contain only alphabets<br/>"
},
mobile: {
required: "Please enter mobile number",
mobilecheck: "Mobile number must contain only numbers "
},
city: "Please enter your current city" ,
jobcity:"please select city" ,
locality:"please enter locality where you are staying",
email: {
email:"Please enter a valid email address",
required:"please enter email address"
},
},
errorElement: "div"
});
});
</script>
My form code is
<form id="myform" method="post" class="register" >
<ul>
<li>
<label for="fullname">Full Name</label>
<input id="fullname" name="fullname" class="required namecheck" size="20" style="width:180px"/>
</li>
<li><label for="email">Email</label>
<input id="email" name="email" class="required email" size="20" style="width:180px" />
</li>
<li>
开发者_如何学编程<label for="mobile">Mobile</label>
<input id="mobile" name="mobile" class ="required mobilecheck" size="20" style="width:180px" maxlength="10"/>
<span id="msgbox" style="display:none"></span>
</li>
<li>
<label for="qualification">Qualification</label>
<input id="qualification" name="qualification" class ="required " size="20" style="width:180px" maxlength="10"/>
<span id="msgbox" style="display:none"></span>
</li>
<li>
<label for="hometown">Home Town</label>
<input id="hometown" name="hometown" class="required" size="20" style="width:180px"/>
</li>
<li>
<label for="city">Current City</label>
<input id="city" name="city" size="20" class="required" style="width:180px"/>
</li>
<li>
<label for="locality">Locality/Neighborhood/Area</label>
<input id="locality" name="locality" class="required" size="20" style="width:180px"/>
</li>
<li>
<label for="jobcity" >Preferred Location for Interview</label>
<select name="jobcity" id="jobcity" clas="required">
<option value=""> -- please select-- </option>
<option value="Bangalore"> Bangalore</option>
<option value="Chennai">Chennai</option>
<option value="Gurgaon">Gurgaon/Noida/Delhi</option>
<option value="Hyderabad"> Hyderabad</option>
<option value="Mumbai">Mumbai</option>
<option value="Pune">Pune</option>
</select></br>
</li>
</ul>
<div style="text-align:center;margin-top:5px;padding-bottom:10px">
<input name="hidden" type="hidden" value="hidden"/>
<input class="blue1 button1" id="#submit" type="submit" value="Submit"/>
</div>
When i submit form in IE, its not validating but submitting form. In chrome and IE .jquery is validating form before submitting.
and i removed unwanted commas from code
Remove the trailing commas
in the below properties, it will work fine. Check for hometown
in rules
and email
in messages
propreties that have a unnecessary comma
at the end. This works fine in all other browser except IE
.
rules: {
fullname: {
required: true, namecheck: true }, mobile: { required: true,
mobilecheck: true
},
city: { required: true },
locality: { required: true },
email: {
required: true, email: true
},
jobcity: { required: true },
hometown: { required: true }
},
messages: {
fullname: {
required: "Please enter your fullname",
namecheck: " Full Name must contain only alphabets<br />"
},
mobile: {
required: "Please enter mobile number",
mobilecheck: "Mobile number must contain only numbers "
},
city: "Please enter your current city",
jobcity: "please select city",
locality: "please enter locality where you are staying",
email: {
email: "Please enter a valid email address",
required: "please enter email address"
}
}
精彩评论