Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Mar 2005
    Posts
    19
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Enable/disable/visible/hide textboxes based on option selected in selected tag

    I need to make a textbox visible and another hidden if a particular option is selected.Though I have a little bit idea I am not getting to anywhere.I request the forum members to help me out.

    Thanking in advance

  • #2
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,037
    Thanks
    0
    Thanked 250 Times in 246 Posts
    Code:
    function hideShowFields(oSel){
      var oFrm = oSel.form;
      switch (oSel.options[oSel.selectedIndex].value){
        case "red":
          oFrm.fieldToShow.style.display='inline';
          oFrm.fieldToHide.style.display='none';
          break;
        //...other cases
      }
    }
    ...
    <select onchange="hideShowFields(this)">
    <option value="blue">Blue</option>
    <option value="red">Red</option>
    ...
    </select>
    <input type="text" name="fieldToShow" style="display:none" value="hello" />
    <input type="text" name="fieldToHide" style="display:inline" value="world" />


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •