Reputation: 413
How to use jquery validation in select option event jquery?
In my script i try these.
<script type="text/javascript">
$("select[name='slc_type']").change(function () {
var ass_con = $(this).val();
switch (ass_con) {
case '1':
case '4':
case '7':
$('#pc_detail').removeAttr("hidden");
$('#printer_detail').prop('hidden', true);
$("#newasset_frm1").validate({
onkeyup: false,
onclick: false,
onfocusout: false,
rules: {
txt_fixasset: "required",
slc_condition: "required",
slc_type: "required",
slc_branch: "required",
slc_department: "required",
ass_description: "required",
slc_brand: "required",
slc_model: "required",
txt_servicetag: "required"
}
});
break;
case '2':
case '3':
$('#printer_detail').removeAttr("hidden");
$('#pc_detail').prop('hidden', true);
$("#newasset_frm1").validate({
onkeyup: false,
onclick: false,
onfocusout: false,
rules: {
txt_fixasset: "required",
slc_condition: "required",
slc_type: "required",
slc_branch: "required",
slc_department: "required",
ass_description: "required",
slc_brand: "required",
slc_address: "required",
txt_street: "required"
}
});
break;
}
});
</script>
But it's not working when i am select on select option. It's not validate when i click on submit by not fill the requirement it's not validate.Any idea??
Upvotes: 0
Views: 247
Reputation: 98718
You're trying to call .validate()
based on a select
element; and this does not make sense. The .validate()
method is only used to initialize the plugin on your form.
You're also trying to call .validate()
attached to the same form with different parameters. The .validate()
method can only be called once, and all subsequent calls are ignored. You cannot dynamically change the options once initialized. One exception is the .rules()
method(s), which allows you to dynamically change the rules.
The .validate()
method should only be called once on the form when the form is created, typically on page load or page ready event. Then within your switch case
you can use the .rules('add')
and .rules('remove')
methods to dynamically change the rules on your form.
See: jqueryvalidation.org/rules/
Upvotes: 1