How to disabled Submit Button after Clicked using jQuery
source link: https://www.laravelcode.com/post/how-to-disabled-submit-button-after-clicked-using-jquery
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
How to disabled Submit Button after Clicked using jQuery
Often times, users like to press a few times on the submit button to make sure the button is surely clicked, and causing the double form submission issue. The common solution is disables the submit button after user clicked on it.
1. Enable / Disable submit button
1.1 To disable a submit button, you just need to add a disabled
attribute to the submit button.
$("#btnSubmit").attr("disabled", true);
1.2 To enable a disabled button, set the disabled
attribute to false, or remove the disabled
attribute.
$('#btnSubmit').attr("disabled", false);
or
$('#btnSubmit').removeAttr("disabled");
2. jQuery full example
<!DOCTYPE html>
<html lang="en">
<body>
<h1>jQuery - How to disabled submit button after clicked</h1>
<form id="formABC" action="#" method="POST">
<input type="submit" id="btnSubmit" value="Submit"></input>
</form>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<input type="button" value="i am normal abc" id="btnTest"></input>
<script>
$(document).ready(function () {
$("#formABC").submit(function (e) {
//stop submitting the form to see the disabled button effect
e.preventDefault();
//disable the submit button
$("#btnSubmit").attr("disabled", true);
//disable a normal button
$("#btnTest").attr("disabled", true);
return true;
});
});
</script>
</body>
</html>
Author : Harsukh Makwana
Hi, My name is Harsukh Makwana. i have been work with many programming language like php, python, javascript, node, react, anguler, etc.. since last 5 year. if you have any issue or want me hire then contact me on [email protected]
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK