118
rated 0 times
[
119]
[
1]
/ answers: 1 / hits: 25227
/ 13 Years ago, fri, november 11, 2011, 12:00:00
I want to validate 2 input fields by comparing one to the other and make sure the second is greater than the first.
Do I need to add a custom method or can I just use the variable name in the range method? If so, can you point me to the syntax?
var validateSection = function (theForm) {
$(theForm).validate({
rules: {
startPoint: {
required: true,
range: [0, 100]
},
endPoint: {
required: true,
range: [startPoint + 1, 100] //Is this possible if I set the function to run on any change to either field?
},
}
});
if ($(theForm).valid()) {
return true;
}
else {
return false;
}
}
Code with Custom Method:
$.validator.addMethod(endGreaterThanBegin, function(value, element) {
return endPoint > startPoint
}, * End Point Should be Greater than Start);
var validateSection = function (theForm) {
$(theForm).validate({
rules: {
startPoint: {
required: true,
range: [0, 100]
},
endPoint: {
required: true,
range: [1, 100],
endGreaterThanBegin: true
},
}
});
if ($(theForm).valid()) {
return true;
}
else {
return false;
}
}
Getting $.validator is undefined before I get to form, and then validateSection is not a function when I start testing input fields
More From » jquery