In this article I will explain with an example, how to use implement Client Side
OnChange event in
jQuery using
CheckBox in
ASP.Net.
HTML Markup
<asp:CheckBox ID="chkHasPassport" Text="Has Passport" runat="server" />
Client Side OnChange event jQuery implementation
First, the following script file is inherited.
1. jquery.min.js
Inside the
document.ready event handler, the
chkHasPassport has been assigned with an
jQuery click event handler.
Note: Here
click event is used instead of change because
change event does not return the current state of the
CheckBox.
When the
CheckBox is
checked or
unchecked, the state of the
CheckBox i.e.
checked or
unchecked is evaluated using
jQuery and then appropriate message is displayed using
JavaScript Alert Message Box.
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/3.7.1/jquery.min.js"></script>
<script type="text/javascript">
$(function () {
$("[id*=chkHasPassport]").click(function () {
var isChecked = $(this).is(":checked") ? "Has Passport - Yes" : "Has Passport - No";
alert(isChecked);
});
});
</script>
Screenshot
Demo
Downloads