Sign In| Join
Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post Dec 11, 2012 01:00 PM by Hyder.Sharief
Member
116 Points
127 Posts
Apr 03, 2012 11:16 AM|LINK
I need to get the selected value of a dropdownlist in my jquery....for this I just used the code as var value = $("#ddlTest option:selected").text(); but for me its not working..whats wrong with this code....can anyone help me
All-Star
78956 Points
13402 Posts
MVP
Apr 03, 2012 11:20 AM|LINK
var value = $("#ddlTest option:selected").html();
Refer
http://jqueryfaqs.com/Questions/Get-Selected-Option-Text-of-HTML-SELECT-Dropdown-using-jQuery.aspx
Contributor
2270 Points
659 Posts
hi
it may help you
html control:
http://csharpektroncmssql.blogspot.in/2012/03/jquery-how-to-select-dropdown-selected.html
asp control:
http://praveenbattula.blogspot.in/2009/08/jquery-how-to-set-value-in-drop-down-as.html
30184 Points
4906 Posts
Apr 03, 2012 11:22 AM|LINK
Hi,
You can simply use-
var value = $("#ddlTest").val(); or
var value = $("select[id$=ddlTest]").val(); // if you have master page or the control is inside usercontrolor
var value = $("select[id*=ddlTest]").val(); // if the control is inside gridview/ repeater kind of control
Star
9337 Points
1447 Posts
$("select[id=ddlTest] :selected").val();
Thanks
Apr 03, 2012 11:30 AM|LINK
no it shows the value as "undefined"
Apr 03, 2012 11:33 AM|LINK
thanks me_ritz for ur response, it shows the value as "undefined", not showing the selected value
Apr 03, 2012 11:34 AM|LINK
Make sure you have Value attribute set in dropdownlist and modify the code as below
$("select[id*=ddlTest] :selected").val();
Apr 03, 2012 11:36 AM|LINK
great asteranup...........actually am using master page, and your second is working fulfilled my requirement.......thanks alot
Apr 03, 2012 11:37 AM|LINK
thanks mudassar for ur response, I tried ur code with simple ddl(not asp), its working fine, but I need to use asp:ddl, and asteranup's code works fine for me,,,,,thanks again for ur response
shanish
Member
116 Points
127 Posts
dropdownlist selected value in jquery
Apr 03, 2012 11:16 AM|LINK
I need to get the selected value of a dropdownlist in my jquery....for this I just used the code as
var value = $("#ddlTest option:selected").text();
but for me its not working..whats wrong with this code....can anyone help me
mudassarkhan
All-Star
78956 Points
13402 Posts
MVP
Re: dropdownlist selected value in jquery
Apr 03, 2012 11:20 AM|LINK
var value = $("#ddlTest option:selected").html();
Refer
http://jqueryfaqs.com/Questions/Get-Selected-Option-Text-of-HTML-SELECT-Dropdown-using-jQuery.aspx
Contact me
bhaskar.mule
Contributor
2270 Points
659 Posts
Re: dropdownlist selected value in jquery
Apr 03, 2012 11:20 AM|LINK
hi
it may help you
html control:
http://csharpektroncmssql.blogspot.in/2012/03/jquery-how-to-select-dropdown-selected.html
asp control:
http://praveenbattula.blogspot.in/2009/08/jquery-how-to-set-value-in-drop-down-as.html
Site:Rare technical solutions
asteranup
All-Star
30184 Points
4906 Posts
Re: dropdownlist selected value in jquery
Apr 03, 2012 11:22 AM|LINK
Hi,
You can simply use-
var value = $("#ddlTest").val(); orvar value = $("select[id$=ddlTest]").val(); // if you have master page or the control is inside usercontrolor
var value = $("select[id*=ddlTest]").val(); // if the control is inside gridview/ repeater kind of controlAnup Das Gupta
Mark as Answer if you feel so. Visit My Blog
me_ritz
Star
9337 Points
1447 Posts
Re: dropdownlist selected value in jquery
Apr 03, 2012 11:22 AM|LINK
$("select[id=ddlTest] :selected").val();
Thanks
shanish
Member
116 Points
127 Posts
Re: dropdownlist selected value in jquery
Apr 03, 2012 11:30 AM|LINK
no it shows the value as "undefined"
shanish
Member
116 Points
127 Posts
Re: dropdownlist selected value in jquery
Apr 03, 2012 11:33 AM|LINK
thanks me_ritz for ur response, it shows the value as "undefined", not showing the selected value
me_ritz
Star
9337 Points
1447 Posts
Re: dropdownlist selected value in jquery
Apr 03, 2012 11:34 AM|LINK
Make sure you have Value attribute set in dropdownlist and modify the code as below
$("select[id*=ddlTest] :selected").val();
Thanks
shanish
Member
116 Points
127 Posts
Re: dropdownlist selected value in jquery
Apr 03, 2012 11:36 AM|LINK
great asteranup...........actually am using master page, and your second is working fulfilled my requirement.......thanks alot
shanish
Member
116 Points
127 Posts
Re: dropdownlist selected value in jquery
Apr 03, 2012 11:37 AM|LINK
thanks mudassar for ur response, I tried ur code with simple ddl(not asp), its working fine, but I need to use asp:ddl, and asteranup's code works fine for me,,,,,thanks again for ur response