0
 $('#err input').bind('blur keyup',function() {
      $(this).data('errors', "ABC " + $(this).data('err') + " " + $(this).val());
   });

 $('#go').click(function(){
   var code = "";
   $("#err input").each(function(){
    code += $(this).data('errors') + "\n" || '';
   });
   $('#x').html(code);
 });

HTML:

<div id="err">
   <input data-err="A" id="e-1" type="text"/>
   <input data-err="B" id="e-2" type="text"/>
   <input data-err="C" id="e-3" type="text"/>
</div> 

How to make validation, if Input will be empty, then this Input not will be processed?

2 Answers 2

1

Try this

$('#go').click(function(){
   var code = "";
   $("#err input").each(function(){
     //This condition will check for empty values
     if($(this).val()){
        code += $(this).data('errors') + "\n" || '';
     }

   });
   $('#x').html(code);
 });
Sign up to request clarification or add additional context in comments.

Comments

0

Returning false from a submit handler cancels the default form submit function. So use:

$('#go').submit(function(){
   //do validation here
   if(validationFails)return false;
 });

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.