Reputation: 43
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
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
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".
Upvotes: 3
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
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