I’ve inherited some code and it has some jquery form validation in it. I have to add a checkbox to the page and would like to use the existing code to validate it, but I’m not sure how to reference the checkbox in this function.
function initValidation() {
$('.validate-form').each(function(){
var form = $(this);
var successFlag = true;
// Added the input:checkbox
var inputs = form.find('input:text, input:password, input:checkbox, textarea, select');
function validateForm() {
successFlag = true;
inputs.each(checkField)
if(!successFlag) {
return false;
}
}
// check field
function checkField(i, obj) {
var currentObject = $(obj);
var currentParent = currentObject.parents('div.row');
// not empty fields
if(currentObject.hasClass('required')) {
setState(currentParent, currentObject, !currentObject.val().length)
}
}
// setState stuff
})
}
I then set the checkbox to “class=required-checkbox” and tried adding
if(currentObject.hasClass('required-checkbox')) {
setState(currentParent, currentObject, currentObject.checked == FALSE);
}
which didn’t work, I also tried
if(currentObject.hasClass('required-checkbox')) {
setState(currentParent, currentObject, currentObject(0).checked == FALSE);
}
and
if(currentObject.hasClass('required-checkbox')) {
setState(currentParent, currentObject, currentObject[0].checked == FALSE);
}
Obviously none of those are right. Can someone tell me how I can be checking that checkbox? I just need to know if its been checked or not.
TIA!
If I’m understanding you right these may help:
Either
Or
Or