HTML CSS Javascript jQuery AJAX PHP Java MORE

How to disable button using Javascript

Sometimes we submit the form two times if the internet is slow or for any other reason. So to prevent this type of error we have to disabled the button after the form submit button is clicked.

So in this example I am explaining how we disabled a button after click.

		<!DOCTYPE html>

		<p>Enter data and submit the form.</p>

		<form id="myForm" action="post.php">
		  First name: <input type="text" name="fname"><br>
		  Last name: <input type="text" name="lname"><br><br>
		  <input type="button" id="btn" onclick="submitForm()" value="Submit form">

		function submitForm() {
		document.getElementById("btn").disabled = true;



Run it yourself