user3809554
user3809554

Reputation: 143

Getting the value of a dropdownlist asp.net using javascript?

I keep getting an error on this saying its undefined or its null. How do I get the drop down lists value?

So far I have:

this._ddlName = $("[id$=ddlName]"), elm);
var split = this._ddlName.value.split('-')[0];

The top line of code is working since I'm using it elsewhere to do something else. But the bottom one throws the error. Any suggestions?

Upvotes: 0

Views: 136

Answers (2)

Kaf
Kaf

Reputation: 33809

Since you are using JQuery:

To get the selected value

$("#id").val();

Upvotes: 1

صفي
صفي

Reputation: 1068

You are missing ()

To get value

$('#dropDownId').val();

To get the currently selected text:

$('#dropDownId :selected').text();

Upvotes: 1

Related Questions