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 5 of 5
  1. #1
    Regular Coder
    Join Date
    Feb 2005
    Posts
    190
    Thanks
    25
    Thanked 0 Times in 0 Posts

    Disable textbox on selecting a value in list

    hi
    how would i go about disabling a text box when a particular value is selected in a list field??!! ive searched CF but could only find radio buttons and textboxes!!

    any help appreciated!!

    vorl

  • #2
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,048
    Thanks
    0
    Thanked 251 Times in 247 Posts
    In this code, selecting "item 3" will disable the textbox and enable it otherwise.

    Script:
    Code:
    function enableDisableText(objSel){
      objSel.form.foo.disabled = (objSel.options[objSel.selectedIndex].value == "3") ? true:false;
    }
    HTML:
    Code:
    <select name="blah" onchange="enableDisableText(this)">
    <option value="1">item 1</option>
    <option value="2">item 2</option>
    <option value="3">item 3</option>
    </select>
    <input type="text" name="foo" />

  • #3
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    PHP Code:
    <script type="text/javascript">
    function 
    dis(f,s){
    f.elements['txt'].disabled=(s==2)?true:false;
    }
    </script> 
    ....
    ...
    <form>
    <select onchange="dis(this.form,this.selectedIndex)">
    <option value="">0</option>
    <option value="">1</option>
    <option value="">disable</option>
    </select>
    <input name="txt" type="text">
    </form> 
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

  • #4
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    ..sorry, we have posted the same time...
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

  • #5
    Regular Coder
    Join Date
    Feb 2005
    Posts
    190
    Thanks
    25
    Thanked 0 Times in 0 Posts
    thanks guys for the quick response!!

    It is just what i needed!!


  •  

    Posting Permissions

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