I need help with a form validator. It validates everything like text and such fine, but I need it to validate whether an unordered list has at least 1 element/item in it.
My initial idea was to count the childNodes in the unordered list, but using .childNodes.length did not work. I’m not sure why, possibly because I have jQuery intermingled in my javascript functions?
Here is an example of the validation function for a text string:
function checkLength( o, n, min, max ) {
if ( o.val().length > max || o.val().length < min ) {
o.addClass( "ui-state-error" );
updateTips( "Length of " + n + " must be between " +
min + " and " + max + "." );
return false;
} else {
return true;
}
}
Here is what my unordered form validation function was (doesn’t work):
function checkTags( t ) {
if (t.childNodes.length < 1) {
t.addClass( "ui-state-error" );
updateTips( "Add at least 1 genre/subgenre." );
return false;
}
else {
return true;
}
}
The unordered list is populated by the user, after selecting values from a select list and clicking a javascript link, if that matters. Thanks in advance for any help!
assuming
tis a jQuery object, tryhere’s a link for your reference: http://api.jquery.com/children/