www.webdeveloper.com
Results 1 to 4 of 4

Thread: hide/remove an option inside select field

  1. #1
    Join Date
    Mar 2011
    Posts
    39

    hide/remove an option inside select field

    hello

    I have this:

    <select name="repeat_period">
    <option value="24">daily</option>
    <option value="168">weekly</option>
    </select>

    and my goal is to auto-remove/hide daily item for force to chose weekly without need to click on a button or link.

    PRECISION: I don't have access to html of the page. I can only include code inside a JS file for try to make modification and I don't know javascript. Is 2 hours I try some solution by mixing code found on some blog..but without success of course.

    Any clue ?

    many thank

  2. #2
    Join Date
    May 2006
    Location
    Somewhere behind your screen
    Posts
    1,656
    Code:
    <!DOCTYPE html>
    <html>
    <head>
    <meta http-equiv="content-type" content="text/html; charset=utf-8" />
    <title>Auto remove an option</title>
    </head>
    <body>
    <center>
    <select name="repeat_period">
    <option value="24">daily</option>
    <option value="168">weekly</option>
    </select>
    </center>
    <script type="text/javascript">
    function removeIt(){
    var sel=document.getElementsByName('repeat_period')[0];
    sel.options.remove(0);
    }
    setTimeout('removeIt()',2000);// timed out just for demonstration
    // remove the above line and uncomment the below line to remove the option immediately
    // removeIt(); 
    </script>
    </body>
    </html>

  3. #3
    Join Date
    Mar 2011
    Posts
    39
    your rock you made my day!!! Long life to you and many thank for your help

    All the best

  4. #4
    Join Date
    May 2006
    Location
    Somewhere behind your screen
    Posts
    1,656
    you're welcome ))

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