Home » Javascript

JavaScript - Disable Button after Click using JavaScript Function

In this code snippet we will learn how to disable a button on click event. In this example there will be button and it will be disabled after click on the button.

JavaScript Code Snippet – Function to Disable Button on Click

JavaScript function

<script type="text/javascript">
	function disableButton(btn){
		document.getElementById(btn.id).disabled = true;
		alert("Button has been disabled.");
	}
</script>

HTML Source Code with JavaScript

<!--JavaScript - Disable Button after Click using JavaScript Function.-->
<html>
	<head>
		<title>JavaScript - Disable Button after Click using JavaScript Function.</title>
		<script type="text/javascript">
			function disableButton(btn){
				document.getElementById(btn.id).disabled = true;
				alert("Button has been disabled.");
			}
		</script>
	</head>

	<body style="text-align: center;">
		<h1>JavaScript - Disable Button after Click using JavaScript Function.</h1>
		<p><input type="button" id="btn1" value="Click to disable button." onclick="disableButton(this)"</p>

	</body>

</html>

Result

JavaScript function to disable button




Comments and Discussions

Ad: Are you a blogger? Join our Blogging forum.



Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing » Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.