How to disable a control in javascript

document.getElementById("ctrl").disabled = true; 

this works in IE but does not work in mozila. What am I doing?

+4
source share
3 answers

Have you tried:

 document.getElementById("ctrl").setAttribute('disabled', true); 
+17
source
 <body> <input id="btnSubmit" type="button" value="submit" onclick="disabled(this);"/> <script> function disabled(ctrl) { ctrl.disabled = true; } </script> </body> 
+3
source

It is hard to say what the problem is that you have. do anything when code is running? Is an error displayed? What version of have you checked this with? And can you also provide html for the ctrl element?

One of the problems with IE and the getElementById method is that in some versions of the browser it will match the id attribute of the tag, as well as the name attribute (which does not follow the JavaScript specification ). In Mozilla, it only matches the id attribute.

0
source

All Articles