Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

getting item # of currently selected item in DropDownList 1

Status
Not open for further replies.

RickLiebespach

Programmer
Sep 29, 2003
85
0
0
US
I forget who, but someone gave me a piece of JavaScript to get the data from a TextBox on a web page. I modified it to get information from a ListBox and a DropDownList.

I need one more piece of information to get it to do what I currently need.
I need to know which item is the currently selected item of my DropDownList.

As an example,
My DropDownList has three items in it...
ddlMyList[0] = "Low"
ddlMyList[1] = "Medium"
ddlMyList[2] = "High"

My page is displaying "Medium" in the DDL
How do I tell my JavaScript that it's item 1 ... the second item?
What I need to know is What do I set "ddlPriorityItemNumber" to...
and
How do I set it?

For reference, here's my JavaScript

function SetAlarm()
{
var myAlarmTime;
var myAlarmMessage;
var ddlPriorityItemNumber;

ddlPriorityItemNumber = 0;

myAlarmTime = GetReminderTimeTextBoxValue();

myAlarmMessage = "";
myAlarmMessage = "Priority: " + GetddlPriorityMessage(ddlPriorityItemNumber) + "\n";

top.FrameHeaderStatic.SetMyAlarm(myAlarmTime, myAlarmMessage);
}


function GetReminderTimeTextBoxValue()
{
var oTextBox = document.getElementById("txtReminderMaintenanceActivityAlarm_Status")
return oTextBox.value
}


function GetddlPriorityMessage(MyItem)
{
var oListBox = document.getElementById("ddlReminderMaintenanceActivityPriority")
return oListBox.options[MyItem].text
}


TIA,

Rick Liebespach
 
Use the selectedIndex method. Here's an example:
Code:
<script language=JavaScript>

</script>
<body>
<form name=blahForm>
<select name=blahSelect>
<option value=zero>zero
<option value=one>one
<option value=two>two
<option value=three>three
<option value=four>four
<option value=five>five
</select>
<br>
<input type=button value='click me' onclick='alert(blahForm.blahSelect.selectedIndex)'>
</form>
</body>

-kaht

banghead.gif
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top