Home > database >  Asp.net Razorpage: Eventhandler on Checkbox is not firing
Asp.net Razorpage: Eventhandler on Checkbox is not firing

Time:09-21

I am trying to react to state changes of my checkbox:

                                                <td>
                                                    @Html.CheckBoxFor(m => m.checkLangs[0].isChecked, new { onchange = "checkedChanged" })


                                                    <script>
                                                        var checkedChanged = function () {
                                                            alert("checkedChanged");
                                                        }
                                                    </script>

                                                </td>

But unfortunaltey, I do see the checkbox but I do not see the alert.

CodePudding user response:

Try to use onchange = "checkedChanged()",and you'd better don't put script into <td></td>:

    <td>
        @Html.CheckBoxFor(m => m.checkLangs[0].isChecked, new { onchange = "checkedChanged()" })

    </td>
    ...
    <script>
            var checkedChanged = function () {      
                 alert("checkedChanged");
            }
    </script>
  • Related