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 4 of 4

Thread: Enable Setect

  1. #1
    New Coder
    Join Date
    Apr 2005
    Posts
    16
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question Enable Setect

    How do you enable and disable a SELECT field onClick of an input button?

  • #2
    New to the CF scene
    Join Date
    Apr 2005
    Location
    Norway, Haugesund
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts
    You could use something like this:

    Code:
    <script type="text/javascript">
    <!--
    function switchDisabled( elemID ) {
    var elem = document.getElementById(elemID);
    if( elem.disabled == true )
    elem.disabled = false;
    else
    elem.disabled = true;
    }
    //-->  </script>
    And then use the button and select list like this:

    Code:
    <input type="button" onclick="switchDisabled('select-list')" value="Switch" />
    <select id="select-list">
    <option value="1">Option 1</option>
    <option value="2">Option 2</option>
    </select>

  • #3
    New Coder
    Join Date
    Apr 2005
    Posts
    16
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Thumbs up

    Thats perfect, Thank You.


  • #4
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,037
    Thanks
    0
    Thanked 250 Times in 246 Posts

    Shorter solution

    <input type="button" onclick="this.form.elements['select-list'].disabled = !this.form.elements['select-list'].disabled" value="Switch" />
    <select id="select-list" name="select-list">
    <option value="1">Option 1</option>
    <option value="2">Option 2</option>
    </select>


  •  

    Posting Permissions

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