Home > ASP.Net, Javascript > How to get Selected ListBox Item using JavaScript

How to get Selected ListBox Item using JavaScript


Hi all,

try this example to get Selected ListBox Item using JavaScript


<head runat="server">
 <title></title>
 <script type="text/javascript">
 function MethodCall() {
 var list = document.getElementById('ListBox1');
 var indx = list.selectedIndex;
 Val.innerHTML = list[indx].value;
 document.location.href = 'Details.aspx?Val=' + list[indx].value;
 }
 </script>
</head>
<body>
 <form id="form1" runat="server">
 <div>
 <asp:ListBox ID="ListBox1" runat="server">
 <asp:ListItem>Microsoft</asp:ListItem>
 <asp:ListItem>Oracle</asp:ListItem>
 <asp:ListItem>Adobe</asp:ListItem>
 <asp:ListItem>Apple</asp:ListItem>
 </asp:ListBox>
 <br />
 <div id="Val"></div>
 <br /><br />
 <input id="Button1" type="button" value="Click Me" onclick="MethodCall()"/>
 </div>
 </form>
</body>
</html>

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: