Friday, 30 March 2012

How to create jump menu or dorpdown or select option in javascript?

Definition: Jump menu/dropdown menu/select  menu

Sometimes we need to show various option to user. By using <select> tag we can achieve this.
in .Net by using DropDownList control. Here, I have use <select>.

Example:-
As user select any option a new window will open with following selected link.

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="Javascript_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Create Jump Menu and Open new window</title>
    <script language="javascript" type="text/javascript" >

    function jumpto(url)
    {
        if (document.form1.jumpmenu.value != "null")
        {
             open_new_window(url);  //here we are passing the value of selected option
        }
    }
    function open_new_window(URL)
    {
       NewWindow = window.open(URL,"_blank","toolbar=no,menubar=0,status=0,copyhistory=0,scrollbars=yes,resizable=1,location=0,Width=1500,Height=760") ;
       NewWindow.location = URL;
    }

</script>
</head>
<body>
<form name="form1">
<div align="center">
<select name="jumpmenu" onChange="jumpto(document.form1.jumpmenu.options[document.form1.jumpmenu.options.selectedIndex].value)">
  <option>Jump to...</option>
  <option value=http://arcreview.blogspot.in/>Arc's Review</option>
  <option value=http://www.google.com>Google</option>
  <option value=http://www.yahoo.com/javascript/>Yahoo</option>
  <option value=http://www.facebook.com/html/>Facebook</option>
 </select>
</div>
</form>
</body>
</html>
 

No comments:

Post a Comment