www.webdeveloper.com
Results 1 to 5 of 5

Thread: disable a dropdown

  1. #1
    Join Date
    Nov 2012
    Posts
    4

    disable a dropdown

    Greetings,

    I have an application which uses a dropdown for one of the fields. After making a choice in this dropdown and setting another field, I query a database and return information to the page. When the page has been reset with the info, I need the dropdown, with its selection set, to be disabled, as the user should not beable to change this at this point, as it is a part of the key. I have tried to use document.getElementById('dropdown').disabled = true but no success. Any ideas? Thanks in advance.

  2. #2
    Join Date
    May 2006
    Location
    Somewhere behind your screen
    Posts
    1,672
    Code:
    <!DOCTYPE html>
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title>ttl</title>
    <style type="text/css"></style>
    <script type="text/javascript">
    function sw(){
    var elem=document.getElementById('sel'),btn=document.getElementById('switcher');
    if(!elem.disabled){elem.disabled='disabled';btn.value="Switch it on";}
    else{elem.disabled=false;btn.value="Switch it off";}
    }
    window.onload=function(){document.getElementById('switcher').onclick=function(){sw();}}
    </script>
    </head>
    <body>
    <center>
    <select id="sel">
    <option>1</option>
    <option>2</option>
    <option>3</option>
    <option>4</option>
    <option>5</option>
    </select>
    <br /><br />
    <input id="switcher" type="button" value="Switch it off" /><br />
    </center>
    </body>
    </html>
    Last edited by Padonak; 01-16-2013 at 05:37 PM.

  3. #3
    Join Date
    Nov 2012
    Posts
    4
    Thank you for the reply Padonak, however, setting the disabled property to disabled did not work either. I am still able to change the selection which is what I need to prevent. I had thought this part would be rather simple, but it has proven to be quite a challenge.

  4. #4
    Join Date
    Nov 2012
    Posts
    4
    Ok. i figured out why this wasn't working for me. I was missing and = in i < 2, therefore I was not making it to the correct selection and skipping the area where I set it to disabled. Correction made and now it works like a charm.

    Thanks for the help.

  5. #5
    Join Date
    Nov 2012
    Posts
    4
    should be "missing an ="

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles