Actually I am validating a form that has text, select, dropdown et-al fields. I have some of the fields that are mandatory and I have given them a class required(only textfields). Now I want to loop through all the form elements and check if that element has a class required, then append a * after that field. I have used each() method, but I don't get it to work exactly as how I want it to be.
My code looks like this:
function validate_form() {
$("#mysubmit").each(function() {
if($("form :text.required:text").val() == "" )
{
$("form :text.required:text").html("*");
return false;
}
return true;
});
}
where mysubmit is the id of my submit button.
I want to traverse the DOM elements one by one. Can anyone help as how do I validate this form. Thanks