Home > ASP.Net, Javascript > Accessing DropDownList Contents using javascript

Accessing DropDownList Contents using javascript


Hi

try this example to Accesse DropDownList Contents using javascript

<script type = "text/javascript">

function getSelected()
{
var ddlist=document.getElementById('<%=DropDownList1.ClientID%>');
var val = ddlist.options[ddlist.selectedIndex].value;
var text = ddlist.options[ddlist.selectedIndex].text;
alert(val);
alert(text);
}

</script>

<div>

<asp:DropDownList ID="DropDownList1" runat="server">
<asp:ListItem Text = "1" Value = "1"></asp:ListItem>
<asp:ListItem Text = "2" Value = "2"></asp:ListItem>
<asp:ListItem Text = "3" Value = "3"></asp:ListItem>
</asp:DropDownList>

<input id="Button1" type="button" value="button" onclick = "getSelected()"/>

</div>

Hope this helps

Good Luck

Advertisements
Categories: ASP.Net, Javascript
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: