| Author: Vidhya 30 Jul 2008 | Member Level: Gold | Rating: Points: 1 |
hi,
HTML 4 knows an attribute named disabled for HTML form controls, it is scripted as the property of the same name so to have a form that enables a select if a certain option of another select is selected have a look at the following example:
<html> <head> <title>disabling/enabling a form control</title> </head> <body> <form name="formName"> <select name="select1" onchange="if (this.selectedIndex == 3) { this.form.elements.select2.disabled = false; } else { this.form.elements.select2.disabled = true; }"> <option>option 1</option> <option>option 2</option> <option>option 3</option> <option>option 4</option> <option>option 5</option> </select> <select name="select2"> <option>option 1</option> <option>option 2</option> <option>option 3</option> <option>option 4</option> <option>option 5</option> </select> <script type="text/javascript"> document.forms.formName.elements.select2.disabled = true; </script> </form> </body> </html>
Note that script is used to disable the select initially as a select disabled statically with HTML would mean the user needs JavaScript enabled to make use of the form.
Note:
rate this content if it is useful!
|