how can i check with jquery that an item is selected or not in listbox?
+1
A:
The :selected selector works for elements. It does not work for checkboxes or radio inputs; use :checked for them.
+1
A:
check the following example that change textbox
with value clicked in asp listbox
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<script type="text/javascript" language="javascript" src="http://code.jquery.com/jquery-1.4.2.min.js"></script>
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:ListBox ID="ListBox1" runat="server" Width="50px" Height="100px"
SelectionMode="Multiple">
<asp:ListItem Value="One">1</asp:ListItem>
<asp:ListItem Value="Two">2</asp:ListItem>
<asp:ListItem Value="Third">3</asp:ListItem>
<asp:ListItem Value="Four">4</asp:ListItem>
<asp:ListItem Value="Five">5</asp:ListItem>
</asp:ListBox>
<br />
<asp:TextBox ID="text1" runat="server"></asp:TextBox>
</div>
</form>
</body>
</html>
<script type="text/javascript">
$('#ListBox1').click(function() {
$("input#text1").val($("#ListBox1 option:selected").val());
});
</script>
Space Cracker
2010-07-21 08:24:38