faqts : Computers : Programming : Languages : JavaScript : Forms : SELECT

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

14 of 15 people (93%) answered Yes
Recently 10 of 10 people (100%) answered Yes

Entry

How do i enable another form element, based on a selection ? eg, Select Other, specify others: text.

Nov 16th, 2004 05:57
Russ Locke, Hermizan Jumari,


Here is an example of enabling selections from another selection. The 
concept would be the same for any form object type.
<html>
<script language="javascript">
  var lastObject = null;
  function toggleObject(objectID) {
    if (lastObject!=null) {
      document.getElementById(lastObject).disabled=true;
    }
    lastObject = objectID;
    document.getElementById(objectID).disabled=false;
  }
</script>
<body>
  object: <select onChange="toggleObject(this.value);">
            <option>select...<option value="color">color
            <option value="digit">digit
          </select>
  color: <select id='color' disabled>
          <option>select...<option>red<option>green
          <option>blue
         </select>
  digit: <select id='digit' disabled>
          <option>select...<option>1<option>2<option>3<option>4
          <option>5<option>6<option>7<option>8<option>9<option>0
         </select>
</body>
</html>