JavaScript dropdown list menu to switch any page

E-mail Print PDF

JavaScript dropdown list menu to switch any page

In this article we are going to design a JavaScript dropdown list menu to switch any page. Some time we have provided option to Select a desire option and load that a web page with respect to it. The Script we are going to design is very simple. First of all just design a select menu. All we have to do is design a form and a drop-down list box. Following piece of code will do it for you.

<form method="post">
<select name="url" onchange="switchpage(this)">
<option value="http://www.xfunda.com">Xfunda Home</option>
<option value="" selected="selected">Redirect to...</option>
<option value="http://www.xfunda.com/forum">Xfunda Forums</option>
<option value="http://www.tipsntracks.com">.Net Tips n Tracks</option>
</select>
</form>

As the user select any option from the list box. The onchange event triggers the switchpage(this) function which gets called with the index of the drop-down list box. switchpage() is the function which will take care of switching to any page. Now we define switchpage(this).

<script language="javascript" type="text/javascript">
function switchpage(select) {
var index;
for(index=0; index<select.options.length; index++)
if(select.options[index].selected)
{
if(select.options[index].value!="")
window.location.href=select.options[index].value;
break;
}
}
</script>

example:

Take a look on live demo...

Source Code:

Download Source code for 'JavaScript dropdown list menu to switch any page'

Download

Trackback(0)
Comments (7)Add Comment
reduce drop-down box
written by rupesh, January 09, 2009
i want to reduce the drop-down box in jsp if i am putting a lot of name than it comes to very big so plz want to reduce
Re: reduce drop-down box
written by Chetankumar Akarte, January 10, 2009
Hi Rupesh,

you can use following code to reduce size...



Regards
Chetankumar Akarte
http://www.xfunda.com
target
written by Stefen, March 12, 2009
... is it possilble to integrate a target option?
Re:target
written by Chetankumar Akarte, March 13, 2009
You have to use window.open() instead of .href

Following piece of code will do it for you.

newWindow = window.open(select.options[index].value);
newWindow.focus( );

Regards
Chetankumar Akarte
http://www.xfunda.com
...
written by Vagelis, March 13, 2009
This is really very helpful but I would like to use that piece of code with a "button" and not with the command "onchange". Could you please tell me which part of the first code you use I have to change?
excellent
written by rafael, March 21, 2009
very good! smilies/grin.gif
Developer
written by derek, August 20, 2009
Wow! Thanks for some code that actually worked the first time. Exactly what I was looking for and I was able to just drop it into my program and it worked!

Write comment
quote
bold
italicize
underline
strike
url
image
quote
quote
smile
wink
laugh
grin
angry
sad
shocked
cool
tongue
kiss
cry
smaller | bigger

busy
Last Updated ( Saturday, 06 December 2008 18:10 )  

Who's Online

We have 20 guests online

Subscribe Feeds

Enter your email address:

Sponsor Adds



Submit Article

We want to develop such a Community portal which will provide a good resource on latest hot technologies such as .NET, VB.NET, C#.NET, ADO.NET, ASP.NET, PHP, Flash, Photoshop. If you like to write for us, this guideline for you. please send your article, faqs on admin[at]xfunda.com

Adobe Gallery Photoshop Tutorials...

Navi Avatar Photo Manipulation with Photoshop Navi Avatar Photo Manipulation with Photoshop Navi Avatar Photo Manipulation with Photoshop Categoty - Photoshop >> Photo Effects. ...
 
Gunshot Through a Glass Photoshop Tutorial Gunshot Through a Glass Photoshop Tutorial Gunshot Through a Glass Photoshop Tutorial Categoty - Photoshop >> Photo Effects. ...
 
How to Create an Abstract Image in Photoshop How to Create an Abstract Image in Photoshop How to Create an Abstract Image in Photoshop Categoty - Photoshop >> illustration and Art. ...
 
How to Create a Clean 3D Notepad in Photoshop How to Create a Clean 3D Notepad in Photoshop How to Create a Clean 3D Notepad in Photoshop Categoty - Photoshop >> illustration and Art. ...
 
Create an Amazing website Layout Using Textures Create an Amazing website Layout Using Textures Create an Amazing website Layout Using Textures Categoty - Photoshop >> Website Designing. ...