HTML/JavaScript - Disable Select Box
Disable control for a Select Box
Try It
Overview
Sometimes it is necessary to prevent the user from changing the value of a select box. The HTML 4.0 specification defines the DISABLE attribute for the SELECT tag. This attribute can be accessed with the JavaScript disable read/write property.
Other Form elements also have the disable attribute/property. This includes BUTTON, INPUT, OPTGROUP, OPTION, SELECT, and TEXTAREA.
Example syntax to disable a select box via HTML
<select name="sel2" disabled>
Example syntax to disable a multiple select box via HTML
<select name="sel3" size="2" multiple disabled>
Compatibility
2002-02-06 - The "Try It" example has been tested and works in Internet Explorer 5.0 and Netscape 6.1. It has been tested and does not work in Netscape 4.74. The disable attribute/property should work in any browser that supports HTML 4.0 and W3C DOM Level 1.2004-09-27 - Tested again with newer browsers. Works in Firefox 1.0PR, Mozilla 1.7.3, Netscape 7.1, Opera 7.54, and IE 6.0.
IE
DISABLED Attribute | disabled Property
http://msdn.microsoft.com/workshop/author/dhtml/reference/properties/disabled_0.asp
W3.org
Interface HTMLSelectElement
http://www.w3.org/TR/2000/WD-DOM-Level-1-20000929/level-one-html.html#ID-94282980
"Try It" Source
Public Domain
The HTML and JavaScript listed below are released to the public domain. Read the Terms of Use for details. The contents of this page are still copyrighted.
Below is a full example of the "Try It" at the top of this page. It shows how to enable/disable a Select box dynamically with JavaScript. Included is a checkbox that uses the click event to enable/disable the select box.
<html> <body> <script language="JavaScript"> <!-- function disable(disableIt) { document.frm.sel.disabled = disableIt; } //--> </script> <form name="frm"> <select name="sel"> <option value="1">one</option> <option value="2">two</option> </select> <br /> <input type="checkbox" onclick="disable(this.checked)" /> Disable </form> </body> </html>