Been too long since I did any JS or jquery, and suddenly I had no clue on how to check or uncheck a checkbox.
What I wanted was when I click on Text beside a checkbox it will toggle the checkbox, took me a couple of minutes to do it.
This site helped: http://www.electrictoolbox.com/check-uncheck-checkbox-jquery/
So the end product is simply:-
<span>
<asp:CheckBox ID="cb_toggler" runat="server" />
<a href="#" onclick="ToggleCheckTheCheckBox ()">Click to check the checkbox</a>
</span>
function ToggleCheckTheCheckBox () {
if ($("#<%=cb_toggler.ClientID%>").is(':checked')) {
$("#<%=cb_toggler.ClientID%>").attr('checked', false);
}
else {
$("#<%=cb_toggler.ClientID%>").attr('checked', true);
}
}
No comments:
Post a Comment