Wednesday, July 14, 2010

Searching and Multipal Selection Criteria in JQuery



<div>
<div style="float: left; width: 150px">
Your Gender :
</div>
<div style="float: left; width: 250px">
<asp:RadioButtonList ID="rdbGender" runat="server">
<asp:ListItem Text="Male" Value="1"></asp:ListItem>
<asp:ListItem Text="Female" Value="0"></asp:ListItem>
</asp:RadioButtonList>
</div>
</div>
<div style="clear: both">
<div style="float: left; width: 150px">
Searching :
</div>
<div style="float: left; width: 250px">
<asp:RadioButtonList ID="rdbSearching" runat="server">
<asp:ListItem Text="Groom" Value="1"></asp:ListItem>
<asp:ListItem Text="Bride" Value="0"></asp:ListItem>
</asp:RadioButtonList>
</div>
</div>

<script type="text/javascript" language="javascript">
$(document).ready(function() {
$("input[id*='rdbGender'], input[id*='rdbSearching']").click(function() {

var foundIn = $(this).attr('id').toString().search(new RegExp(/rdbGender/i));

var strOpositeRadioButton = "rdbGender";

if (foundIn > -1) {
strOpositeRadioButton = "rdbSearching";
}

if ($(this).val() == 1) {
$("input[id*=" + strOpositeRadioButton + "][value=0]").attr("checked", "checked");
}
else {
$("input[id*=" + strOpositeRadioButton + "][value=1]").attr("checked", "checked");
}
});
});
</script>

No comments: