I wanted to check validation of certain field before submitting a form.
<form method="post" action="test.do">
<input type="file" id="file1" />
<input type="file" id="file2" />
<input type="file" id="file3" />
<input type="button" id="submitButton" />
</form>
I only want to check validation of id = file2 & file3. It should not be left blank.
$("#submitButton").click(function() {
if(validate()){
$(this).closest("form").submit();
}
});
function validate() {
/* if blank return false else true */
how to validate here ??
}
*Note : * as I have hundreds of fields to check, it’d be very lengthy to use id for validation.
Is there any other way to check ?
I would add a class attribute to the validated fields:
And then do some validation with the jQuery selector: $(‘.validate’)