Ask Experts Questions for FREE Help !
Ask
    spyyder's Avatar
    spyyder Posts: 35, Reputation: -2
    Junior Member
     
    #1

    Jan 28, 2006, 09:55 AM
    Drop down menu code
    I need a code that will create a Drop Down Menu (like a standard drop down scroll menu from frontpage), that allows the user to make a selection then redirect to a page that the person selected.

    E.g. drop down menu has the following headings/titles

    ITEM1
    ITEM2
    ITEM3

    When item1 is selected, it automatically redirects to page1.html, and for Item2 it redirects to page2.html, and etc, etc.
    And the default (initial) selected option is 'ITEM1'.
    Thanks.:)
    LTheobald's Avatar
    LTheobald Posts: 1,051, Reputation: 127
    Ultra Member
     
    #2

    Jan 31, 2006, 04:35 AM
    Here's a solution- quick & easy.

    Code:
    <html>
    <head>
    <title>Drop Down Test</title>
    <script language="javascript">
        function redirectMe() {
            var prefix = "";
            window.location = prefix + document.all.redirectSelect.value;
        }
    </script>
    </head>
    
    <body>
    <select name="redirectSelect" onChange="redirectMe()">
        <option value="test.html" selected>Option 1</option>
        <option value="test2.html">Option 2</option>
        <option value="test3.html">Option 3</option>
    </select>
    </body>
    </html>
    Quite simple really. When the select box is changed, the javascript function redirectMe() is called. This checks for the value of the selected element and redirects you to it.

    Note I've also included a blank variable called "prefix". This could be used to make the HTML code shorter. For example, say you want to redirect to the following pages:

    https://www.askmehelpdesk.com/forumdisplay.php?f=15
    https://www.askmehelpdesk.com/forumdisplay.php?f=365
    https://www.askmehelpdesk.com/forumdisplay.php?f=57

    You could set prefix to "https://www.askmehelpdesk.com/forumdisplay.php?f=". Then in the HTML you would just need to set the value to the remaining portion of the address (the number). Here's the code to explain what I mean:


    Code:
    <html>
    <head>
    <title>Drop Down Test</title>
    <script language="javascript">
        function redirectMe() {
            var prefix = "https://www.askmehelpdesk.com/forumdisplay.php?f=";
            window.location = prefix + document.all.redirectSelect.value;
        }
    </script>
    </head>
    
    <body>
    Ask Me Help Desk Forums:
    <select name="redirectSelect" onChange="redirectMe()">
        <option value="15" selected>Technology & the Web</option>
        <option value="365">Forum Community</option>
        <option value="57">Building Web Pages</option>
    </select>
    </body>
    </html>
    Hope that helps. Any problems - post a reply here and I'll get on it.

    *** EDIT ***
    And now I see the asker was banned! Oh well, it might help someone else :)

Not your question? Ask your question View similar questions

 

Question Tools Search this Question
Search this Question:

Advanced Search

Add your answer here.


Check out some similar questions!

Menu Items [ 1 Answers ]

How to Enable / disable Menu Items For Windows Programming If Program is to be written in Visual C++

Slow start menu [ 3 Answers ]

I'm running win98 on a refurbished IBM netvista, Pentium II. I've noticed over the last few weeks that my start menu is sporadically very slow. Like, I will click Start, and it will take 30 seconds or more for the menu to pop up. Sometimes it doesn't pop up at all, the computer freezes and I have...

+/- from all programs menu [ 2 Answers ]

How can I add new items to the "all programs" list in XP?:o I'd like to create a entry or two there and move some of the existing items into that folder. Is this possible? Thanks in advance for the help... and oh yeah, Merry Christmas!:D

How can I delete option Win Xp boot menu [ 1 Answers ]

In win xp, the boot menu that offers different os choices contains an invalid listing. How can I delete it?

Want a help menu [ 1 Answers ]

Hi Friends I am A new member to this ASK ME HELP DESK. I want to know the procedures and formalities for how to use this site. For example the word 'THREAD', I don't know the meening of it. Is there any help menu ICON for it to click on. So that I'll get the answers without disturbing anyone. ...


View more questions Search