Monday, 2 June 2014

How to get Selected ListBox Item using JavaScript


<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script type="text/javascript">
function MethodCall() {
var list = document.getElementById('ListBox1');
var indx = list.selectedIndex;
rep.innerHTML = list.value;
document.location.href = 'http://www.itorian.com?Val=' + list.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="rep"></div>
<br /><br />
<input id="Button1" type="button" value="Click Me" onclick="MethodCall()"/>
</div>
</form>
</body>
</html>