Disable Form Submit Button After Click using JavaScript
In this tutorial, I will explain how to Disable submit button after click using JavaScript
Description:
In previous articles, I explained Get Latitude and Longitude from Zip Code using JavaScript, What is Local Storage and Session Storage and many more articles relating to Angular, Node, React & jQuery. Now I will explain how to Disable submit button after click using JavaScript.
You need to call disabled attribute on submit event. In this example, I have created form submit event. On that event, I’m disabling button using JavaScript
Use The Code:
<script type="text/javascript">
function disableButton() {
var btn = document.getElementById('btn');
btn.disabled = true;
btn.innerText = 'Posting...'
}
</script>
If you want to complete code, you need to write the code like as shown below
Use The Code:
<html>
<head>
<title>disable submit button after click using javascript </title>
<script type="text/javascript">
function disableButton() {
var btn = document.getElementById('btn');
btn.disabled = true;
btn.innerText = 'Posting...'
}
</script>
</head>
<body>
<form method='POST' onsubmit='disableButton()'>
<button id='btn' type='submit'>Post</button>
</form>
</body>
</html>












