Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jquery validation only validates first field - others are ignored

I'm using a jQuery validation plugin which should validate all the inputs in a form, but it stops at the first one. If you click on the second input and leave it blank - everything is ok - it validates...
Otherwise - not...

I found some of the same answers - no success...

Here's my fiddle with the example I wrote

FiddleError

//
//  jQuery Validate example script
//
//  Prepared by David Cochran
//
//  Free for your use -- No warranties, no guarantees!
//

$(document).ready(function(){

// Validate
// http://bassistance.de/jquery-plugins/jquery-plugin-validation/
// http://docs.jquery.com/Plugins/Validation/
// http://docs.jquery.com/Plugins/Validation/validate#toptions

    $('.validate').validate({
        highlight: function(element) {
            $(element).parent().removeClass('has-success').addClass('has-error');
        },
        success: function(element) {
            element.closest().removeClass('has-error').addClass('has-success');
        }
  });

}); // end document.ready`enter code here`

Using:

  • Bootstrap
  • jQuery
  • jQuery validation
like image 227
Modestas MV Avatar asked Sep 24 '13 16:09

Modestas MV


1 Answers

Use name for the fields instead of id

<div class="form-group">
    <label class="control-label" for="login_id">Login id:</label>
    <input type="text" class="form-control required" name="login_id">
</div>
<div class="form-group">
    <label class="control-label" for="password">Password:</label>
    <input type="password" class="form-control required" name="password">
    <div class="forgot"> <a href="#">
                    Forgot your password?
                </a>

    </div>
</div>

Demo: Fiddle

like image 64
Arun P Johny Avatar answered Oct 13 '22 10:10

Arun P Johny