Zain Tahir
Zain Tahir

Reputation: 43

How to disable a submit button in jQuery?

I want to disable or hide a button using jquery after the form has been submitted. I have tried some solutions but nothing happened.. I have included js file in my page.

Here is my submit button code:

 echo '<td>
           <a href="shortlist.php?vid='.$row["v_id"].'&uid='.$row["userid"].'"">
               <input type="submit" value="short list" id="shortlist" name="shortlist">
           </a>
       </td>';

Here is my jQuery code.....

$('input:submit').click( function() {
    console.log("Form is submiting.....");
    $('input:submit').attr("disabled", true);
});

Upvotes: 1

Views: 85

Answers (5)

Vikal Singh
Vikal Singh

Reputation: 84

Try this jquery code after click submit button, it will disable.

$('input[type=submit').click(function(e){
            e.preventDefault();
            console.log("Form is submiting.....");
            $('#shortlist').attr("disabled", "disabled");
        });

Upvotes: 0

Pupil
Pupil

Reputation: 23978

You should use type attribute.

Basically apart from class and id selectors, CSS2 selectors are also supported by jQuery.

$('input[type=submit]').attr("disabled", true);

[att=val] Match when the element's "att" attribute value is exactly "val".

Reference:

Upvotes: 3

Ahmed Malik
Ahmed Malik

Reputation: 179

$('input[type=submit]').prop('disabled', true);

Upvotes: 2

Rahul
Rahul

Reputation: 18577

You can create form submit event to achieve that,

$('form').on('submit', function(){
    $("input[type='submit']").attr("disabled", true);
});

And then just set disabled attribute for input with submit type.

Upvotes: 2

Will Jones
Will Jones

Reputation: 2201

You should use the type attribute and need to set the disabled attribute to 'disabled'

$('input[type=submit').click(function(){
    console.log("Form is submiting.....");
    $('input:submit').attr("disabled", "disabled");
});

Upvotes: 2

Related Questions