This is a migrated thread and some comments may be shown as answers.

Checkbox event not firing

1 Answer 1478 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Edward
Top achievements
Rank 1
Edward asked on 10 Sep 2014, 08:50 PM
I can't seem to get the change event to fire. 

Here's the code:

<div class="k-edit-label">
    @(Html.LabelFor(model => model.IsAllDay))
</div>
<div data-container-for="isAllDay" id="is-all-day" class="k-edit-field">
    <input data-bind="checked: isAllDay" data-val="true" id="isAllDay" name="isAllDay" type="checkbox" />
</div>

I've tried:

$(function () {
    $("#isAllDay").change(function () {
        alert("changed changed");
    });
});

and

<div class="k-edit-label">
    @(Html.LabelFor(model => model.IsAllDay))
</div>
<div data-container-for="isAllDay" id="is-all-day" class="k-edit-field">
    <input data-bind="checked: isAllDay, events: { change: isAllDayChanged}" data-val="true" id="isAllDay" name="isAllDay" type="checkbox" />
</div>
function isAllDayChanged() {
    alert("changed");
}

What am I missing?

1 Answer, 1 is accepted

Sort by
0
Vladimir Iliev
Telerik team
answered on 12 Sep 2014, 06:24 AM
Hi Matt,


From the provided information it seems that the reason for current behavior is that the handlers are not correctly placed in the code (not accessible in the checkbox scope). Please consider the following example which works as expected on our side:

<div data-container-for="isAllDay" class="k-edit-field">
    <input id="isAllDay" name="isAllDay" type="checkbox" data-bind = "checked:isAllDay" />
</div>
<script>
    $(function () {
        /*use the edit event or place the handler inside the editor*/
        $("\\#isAllDay").change(function () {
            alert("changed changed");
        });
    });
</script>

Kind Regards,
Vladimir Iliev
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
Tags
General Discussions
Asked by
Edward
Top achievements
Rank 1
Answers by
Vladimir Iliev
Telerik team
Share this question
or