Javascript Syntax for ASP.Net DropDown List Value

jrothlander

New member
Joined
Feb 7, 2012
Messages
4
Programming Experience
10+
Can someone show me how to use the follow syntax style in javascript to return the selectIndex.value? What seems obvious does not work here.

I can do the standard getElementById() approach, but that takes about 10-lines of code to do the same thing. This works fine when I wante the text value but I cannot figure out how to do this to get the selectedIndex.value.

Anyone know how to do this?

Best regards,
Jon

Code:
[FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff][FONT=Consolas][SIZE=2][COLOR=#0000ff] 
var[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2][COLOR=#000000] authMethod = $([/COLOR][/SIZE][/FONT][/SIZE][/FONT][FONT=Consolas][SIZE=2][COLOR=#800000][FONT=Consolas][SIZE=2][COLOR=#800000][FONT=Consolas][SIZE=2][COLOR=#800000]'select[id$=<%=ddlCredentials.ClientID%>] :selected'[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2][COLOR=#000000]).text(); [/COLOR]
[/SIZE][/FONT][/SIZE][/FONT]
 

nayanpatel

Active member
Joined
Nov 18, 2016
Messages
27
Location
ahmedabad
Programming Experience
3-5
Without a valid dom jQuery cannot work correctly with the selectors.


Just use the selectedIndex property of the DOM element:


alert($("#dropDownMenuKategorie").prop('selectedIndex'));





 
Top Bottom