In this article I will explain with an example, how to implement Client Side
OnChange event in
JavaScript using
CheckBox in
ASP.Net.
HTML Markup
<asp:CheckBox ID="chkHasPassport" Text="Has Passport" runat="server" onclick="OnCheckBoxClick(this)" />
Client Side OnChange event JavaScript implementation
Inside the
document.ready event handler, the
chkHasPassport has been assigned with an
JavaScript 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
JavaScript and then appropriate message is displayed using
JavaScript Alert Message Box.
<script type="text/javascript">
function OnCheckBoxClick(chkHasPassport) {
var isChecked = chkHasPassport.checked ? "Has Passport - Yes" : "Has Passport - No";
alert(isChecked);
};
</script>
Screenshot
Demo
Downloads