/ Published in: JavaScript
Expand |
Embed | Plain Text
//basic form validation if($(".js_validate").length>0){ $('.js_validate').submit(function() { //clear other form validations $('.js_req').removeClass("error"); var errors = new Array(); var el = $(this).attr("id"); var required = $(this).find(".js_req"); required.each(function(i){ if($(this).val()==""){ console.log($(this).val()); errors[i]= $(this).attr("name"); $("#"+el+"").find("input[name='"+$(this).attr("name")+"']").addClass("error"); } }); if(errors.length>0){ return false; alert(errors.length); } else { return true; } }); }
You need to login to post a comment.
