39 users online (0 members and 39 guests)  


  Results 1 to 5 of 5

Related

  1. help with two drop down menus    Forum: Javascript Forum
    Replies: 3
  2. Drop Down Menus    Forum: HTML Forum
    Replies: 6
  3. Drop Down Menus    Forum: HTML Forum
    Replies: 1
  4. Drop down menus    Forum: HTML Forum
    Replies: 0
  5. drop down menus    Forum: HTML Forum
    Replies: 2
  1. #1
    HTMLer's Avatar
    New User

    Status
    Offline
    Join Date
    Nov 2010
    Posts
    17

    Add links to drop down menus

    Hey everyone!

    I am trying to create a drop down menu that can direct the user to a different page once the user selects something.
    Here is a sample of my code:


    Code:
    Background color
    <form action="">
    <select name="options" size="1">
    <option value="default">Default</options>
    <a href="cyan.html">
    <option value="cyan.html">Cyan</option>
    </a>
    <option value="green.html">Green</options>
    </select>
    </form>

    As you can see above I've tried wrapping the word "cyan" with the <a href=""> </a> tag, but once I click Cyan or any other option nothing happens.

    I am still learning HTML, so if possible correct my code using HTML.

    Thanks guys!


    EDIT: sorry if this is already posted, but I searched for this all over the site and I was not able to find anything close related to my question.
    Last edited by HTMLer; 11-29-2010 at 10:54 PM.

  2. #2
    HTMLer's Avatar
    New User

    Status
    Offline
    Join Date
    Nov 2010
    Posts
    17

    Re: Add links to drop down menus

    29 views and no one is willing to help?

  3. #3
    coothead's Avatar
    bald headed old fart

    Status
    Offline
    Join Date
    Aug 2003
    Location
    chertsey, a small town 25 miles south west of london, england.
    Posts
    732

    Re: Add links to drop down menus

    Hi there HTMLer,

    and a warm welcome to these forums.
    29 views and no one is willing to help?
    Viewers can only help if they know a possible solution.
    You must also bear in mind that many viewers may be looking for answers to similar problems.

    As for your problem, it cannot be achieved with HTML alone but requires a little javascript.
    Of course, this method of navigation will be ineffectual for those who have javascript disabled.

    Code:
    
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
       "http://www.w3.org/TR/html4/strict.dtd">
    <html lang="en">
    <head>
    
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <meta name="language" content="english"> 
    <meta http-equiv="Content-Style-Type" content="text/css">
    <meta http-equiv="Content-Script-Type" content="text/javascript">
    
    <title>untitled document</title>
    
    <script type="text/javascript">
    
    function init(){
    
       var df=document.forms[0];
    
    df[0].onchange=function() {
    if(this.value!='') {
       df.action=this.value;
       df.submit();
       }
      }
     }
    
     window.addEventListener?
     window.addEventListener('load',init,false):
     window.attachEvent('onload',init);
    
    </script>
    
    </head>
    <body>
    
    <form action="#">
    <div>
    <select>
     <option value="">- your destination -</option>
     <option value="http://www.google.com/">google</option>
     <option value="http://www.yahoo.com/">yahoo</option>
     <option value="http://www.bbc.co.uk/">bbc</option>
    </select>
    </div>
    </form>
    
    </body>
    </html>
    

  4. #4
    HTMLer's Avatar
    New User

    Status
    Offline
    Join Date
    Nov 2010
    Posts
    17

    Re: Add links to drop down menus

    Thanks coothead!
    I am not there yet, but I will be learning java script soon!
    For now I will save the code above for reference.

  5. #5
    coothead's Avatar
    bald headed old fart

    Status
    Offline
    Join Date
    Aug 2003
    Location
    chertsey, a small town 25 miles south west of london, england.
    Posts
    732

    Re: Add links to drop down menus

    No problem, you're very welcome.