I am making a form validation function and stuck in a place, to solve the problem I want to get the total number of form elements present in a form & also I want to check if all form elements are filled or not.
Function is being called in blur event, below is my code:
(function($){
$.fn.da_form_validation = function(options){
var error_fields = function(){
var form_element_length = $(this).length;
alert(form_element_length);
};
return this.each(function(){
$(this).blur(error_fields);
});
};
})(jQuery);
$(".check_field").da_form_validation();
<form name="sample_form" method="post">
<input class="check_field" type="text" name="first_name" id="first_name" value="" />
<input class="check_field" type="text" name="last_name" id="last_name" value="" />
<textarea class="check_field" name="address" id="address"></textarea>
<input type="submit" name="submitbtn" id="submitbtn" value="Submit" disabled="disabled" />
</form>
Note: Currently Submit button is disabled.
So if above all form fields are filled submit button will be enabled.
Currently if I try to get length of form this way it always gives me 1 instead of 3.
Please help.