Shinu Thomas
Shinu Thomas

Reputation: 5316

Getting Selected name of a dropdown using Javascript

I have created one dropdown box

<select name="select" id="selectId">
<option id="" value="calendar_Second_Calendar_1285942672.xml">Second Calendar</option>
<option id="" value="calendar_First_Calendar_1285932160.xml">First Calendar</option>
</select>

I can get the selected drop down box value using

document.getElementById("selectId").value

How i can get the name where user is seeing i mean (Second Calendar or First Calendar)

Upvotes: 1

Views: 7693

Answers (2)

Skilldrick
Skilldrick

Reputation: 70819

Give this a go:

var domNode = document.getElementById("selectId");
var value = domNode.selectedIndex;
var selected_text = domNode.options[value].text;

Upvotes: 7

Ibrahim
Ibrahim

Reputation: 1261

You can determine the name by a simple if else statements on the given value.

Upvotes: 0

Related Questions