Mike Smith
Mike Smith

Reputation: 185

How to get the Value of a Dropdownlist in Javascript

This is a really simple problem I can't figure out. I am trying to get the value of a dropdownlist using Javascript. I have 4 digit job codes in my dropdownlist. On a button click I got to this function and am trying to get the value of what was selected when a button was pushed.

 function jobCodeToAdd() {

 var jobCode = document.getElementById("<%=jobCode.ClientID%>"));
 var selectedJobCode = jobCode.options[jobCode.selectedIndex].value;

What am I doing wrong? Thank you for your help.

Upvotes: 0

Views: 58

Answers (1)

Mike
Mike

Reputation: 1492

I think what you are looking for is .text

 var jobCode = document.getElementById("<%=jobCode.ClientID%>"));
 var selectedJobCode = jobCode.options[jobCode.selectedIndex].text;

Upvotes: 1

Related Questions