ahmedsaber111
ahmedsaber111

Reputation: 822

Jquery validation and submit handler

I am using jquery validation to validate my form, i want to show the submit button when ever the validation rules passed true,

$(function(){
    $('.newEmp').validate({ 
         submitHandler: function(){ 
            alert("Submitted!");
         },
         rules:{
             email:{
                 required: true,
                 email: true
             },
             first_name:{
                 required: true,
                 minlength: 4
             },
             last_name:{
                 required: true,
                 minlength: 4                
             },
             mobile:{
                 required: true,
                 minlength: 4                
             },
             position:{
                 required: true,
                 minlength: 4                
             }
         }
    });



});

HTML

<div class="blue_button" style="display:none;">
    <button type="submit" id="submit">submit</button>
</div>

where should i put this code to show my submit button

$('.blue_button').css('display', 'block');

Upvotes: 0

Views: 2395

Answers (1)

JNDPNT
JNDPNT

Reputation: 7465

You can trigger validation manually with $('.newEmp').valid(). Than if it passes, you can show the submit button.

Update:

$('.newEmp input').focus(function (){
    if ($('.newEmp').valid()) {
        $('.blue_button').show();
    }
});

Upvotes: 2

Related Questions