Posted by: h4ck@lyst | October 22, 2007

javascript::dropdown menu

The following code is to select the id value of the selected option of a dropdown menu. It includes the html code as well.

<html>
<head>

<SCRIPT LANGUAGE=javascript>
<!–
function OnChange(dropdown)
{
var myindex = dropdown.selectedIndex
var SelValue = dropdown.options[myindex].value
var baseURL = <Some value based on SelValue>
top.location.href = baseURL;

return true;
}

//–>
</SCRIPT>

</head>

<body >

<form name=”form1″>
<select name=”menu” onChange=”alert(‘test::’+document.form1.menu.options[document.form1.menu.selectedIndex].id)” value=”GO”>
<option value=”http://a&#8221; id=”aAnkit”>anshu</option>
<option value=”http://2&#8243; id=”2@bubbles”>2prateek</option>
<option value=”http://3&#8243; id=”3#prajwal”>3pratik</option>
</select>
</form>

</body>
</html>
Basically the format follows as

<!–Document.FormName.SelectName.Options[Document.FormName.SelectName.selectedIndex].Property–>

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Categories

%d bloggers like this: