Ask Experts Questions for FREE Help!
Ask    ||    Answer
 
Advanced  
 

Ask QuestionsprogressAnswer QuestionsprogressBuild ReputationprogressBecome an Expert
 
Free Answers in 3 Easy Steps

Register Now
3 Steps

At Ask Me Help Desk you can ask questions in any topic and have them answered for free by our experts. To ask questions or participate in answering them you must register for a free account. By registering you will be able to:
  • Get free answers from experts in any of our 300+ topics.
  • Accept money for answers that you provide.
  • Communicate privately with other members (PM).
  • See fewer ads.

Home > Computers & Technology > Internet & the Web   »   Drop down menu code

 
Thread Tools Search this Thread Display Modes
Question
 
 
#1  
Old Jan 28, 2006, 08:55 AM
spyyder
Junior Member
spyyder is offline
 
Join Date: Apr 2005
Posts: 36
spyyder See this member's comment history on his/her Profile page.
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.

Reply With Quote
 
     

Answers
 
 
Old Jan 31, 2006, 03:35 AM   #2  
Ultra Member
LTheobald is offline
 
LTheobald's Avatar
 
Join Date: Feb 2004
Location: Cambridge, UK
Posts: 1,047
LTheobald See this member's comment history on his/her Profile page.LTheobald See this member's comment history on his/her Profile page.
Call LTheobald via Skype™ Send a message via MSN to LTheobald
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:

http://www.askmehelpdesk.com/computers-technology/
http://www.askmehelpdesk.com/forum-community/
http://www.askmehelpdesk.com/a/

You could set prefix to "http://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 = "http://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
  Reply With Quote
 
     

Your Answer
Email me when someone replies to my answer
Join Login





Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

 
Similar Sponsors


Thread Tools
Show Printable Version Show Printable Version
Email this Page Email this Page

Similar Threads
Menu Items
(1 replies)
slow start menu
(3 replies)
+/- from all programs menu
(2 replies)
How can i delete option Win Xp boot menu
(1 replies)
Want a help menu
(1 replies)

Search this Thread

Advanced Search

Bookmarks

Sponsors



Copyright ©2003 - 2009, Ask Me Help Desk.
All times are GMT -8. The time now is 04:14 PM.