The following jQuery validate code is supposed to check the form that the user must enter the e_usage field if the e_usagelow field has not been filled in. I wrote the dependency call function for e-usage based on the example at jQuery Validation - Two fields, only required to fill in one, but somehow my function doesnt work (e.g. when putting the mouse on the e-usage field while e_usagelow is empty no validation-error warning appears and the console shows the value 'true')
What goes wrong?
Please your help.
html code:
E-usage: <input id="e_usage" type="text" name="e_usage">
E-usage low: <input id="e_usagelow" type="text" name="e_usagelow" >
javascript code:
$(document).ready(function () {
$("#myForm").validate({
rules: {
'e_usage': {
required: function (element) {
console.log("validation: required: " + $("#e_usagelow").is(':empty'));
return $("#e_usagelow").is(':empty');
},
minlength: 3,
maxlength: 8,
number: true
},
'e_usagelow': {
required: true,
minlength: 3,
maxlength: 8,
number: true
}
} //rules
}); //validate()
}); //function
change 'e_usage'
to e_usage
and 'e_usagelow'
to e_usagelow
id
is not enclosed in quotes
$(document).ready(function () {
$("#myForm").validate({
rules: {
e_usage: { //removed quotes from id
required: function (element) {
console.log("validation: required: " + $("#e_usagelow").is(':empty'));
return $("#e_usagelow").is(':empty');
},
minlength: 3,
maxlength: 8,
number: true
},
e_usagelow: { //removed quotes from id
required: true,
minlength: 3,
maxlength: 8,
number: true
}
} //rules
}); //validate()
});
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다