bind mvc checkbox to javascript function

Trying to bind an mvc helper checkbox with jquery to a javascript function and that function will do something based on the fact that it is checked or not.

PART 1: How do you successfully bind the checkbox to a click or change event?

PART 2: How do you check the checkbox for checked or not?

<div class="editor-label">
    @Html.LabelFor(model => model.Immediate)
<div class="editor-field">
    @Html.CheckBoxFor(model => model.Immediate, new {id = "chkImmediate" })

My attempt at binding:


function clickEvent() {
        alert($("#chkImmediate").checked); //want it to show true/false



Assumming the id of the checkbox is correct, you can bind the event using jQuery like this:

$("#chkImmediate").change(function() {
    if(this.checked) {
        alert('It's checked!!');
    } else {
        alert('It's not checked!!');


Recent Questions

Top Questions

Home Tags Terms of Service Privacy Policy DMCA Contact Us

©2020 All rights reserved.