javascript - Show error only in empty fields -



javascript - Show error only in empty fields -

jquery(function($){ var fields = $('.registerform'); fields.blur(function(){ var field = $(this); var text = field.context.id; if(field.val().length == 0 || field.val() == 0){ $('#' + text).addclass('error') } if(email.val().length && email_match.val().length > 0) { if(email.val() !== email_match.val() || field.val().length == 0){ $('#email, #email_match').addclass('error') } else { $('#email, #email_match').removeclass('error') } } }); fields.focus(function(){ var field = $(this); var text = field.context.id; if(field){ $('#' + text).removeclass('error') } }); });

this peace of code adds class error empty inputs or if email , pass not equals. want same when pressing submit must give class empty spaced.

$('#registerform').on('submit', function(e){ if(fields.val().length == 0 || fields.var() == 0) //give empty area's class error e.preventdefault(); });

how do ?

the form id registerform , inputs has class registerform

how this:

$('#registerform').on('submit', function(e){ //give empty area's class error e.preventdefault(); fields.each(function() { if ($(this).val().length == 0 || $(this).var() == 0) { $(this).addclass('error'); } }); });

javascript jquery

Comments

Popular posts from this blog

Delphi change the assembly code of a running process -

json - Hibernate and Jackson (java.lang.IllegalStateException: Cannot call sendError() after the response has been committed) -

C++ 11 "class" keyword -