0

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');

3
  • 1
    Is there an option that lets you set a callback for validation passing? Commented Jan 17, 2013 at 7:50
  • your form is validated only after you submit the form...so hidding it before doesnot make sense Commented Jan 17, 2013 at 7:53
  • so how could i make it validate onfocus Commented Jan 17, 2013 at 7:54

1 Answer 1

2

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();
    }
});
Sign up to request clarification or add additional context in comments.

1 Comment

See the updated example code. On focus of your input elements (in this case, you can extend the selector) it will validate your form and if everything is valid show the submit button.

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.