"onclick="this.disabled=true;" doesn't work

Hello guys,

I have a form on some pages and I’m trying to make submit button disabled when user submits form.

I googled for it and found this solution:


But it doesn’t work. How can I make this code work?

i dont know much about this keyword i’am little confuse use that keyword if not used at oop coding.

have a read to this tutorial

that is enough easy for navigating the form as you like after reading the tutorial

Try the onsubmit event of the form.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
	<meta http-equiv="content-type" content="text/html; charset=utf-8" />
	<title>Event Delegation</title>
	<script type="text/javascript">
	window.onload = function() {
		var frm = document.getElementById("formId");
		frm.onsubmit = function() {
			document.getElementById("btnSubmit").disabled = true;
			return false;
<form action="" method="post" id="formId">
<input type="submit" value="Submit" name="btnSubmit" id="btnSubmit" />

Don’t leave ‘return false’ in there, it stops the form submitting.

Perhaps you’ve just forgotten the closing quotation mark.

<input type="submit" value="Submit" onclick="this.disabled=true;">

Although I agree with r51 in that javascript should be kept outside the HTML, in the <head>.

Thanks. This code works.

Don’t leave ‘return false’ in there, it stops the form submitting.

What do you mean? I should remove line “return false” from the code?

I think returning false should have no effect on the form submission. If you were to want to stop it submitting you would have to use preventDefault() for non-IE browsers and window.event.returnValue = false for IE.

Quotation mark is there, but onclick=“this.disabled=true;” doesn’t work.

<input type="submit" onclick="this.disabled=true">

This works for me in Firefox. I clicked and it disabled itself. Don’t see why it shouldn’t work in other browsers.

I’m pretty sure ‘return false’ at the end of the onsubmit event handler prevents submission. It certainly does for the code I posted.
I think when you start to use the more flexible event model with listeners, then you need to start working with preventDefault etc.

You use return false when it’s an inline event handler and the others when it isn’t. That’s how it is with onclick and onmouseover at least, so I would expect it to be the same for onsubmit.