javascript - onclick in ASP.NET MVC razor CheckBoxFor not working -


i need assign onclick event checkboxfor in asp.net mvc razor, never called.

i have this, not work:

<script type="text/javascript">     function setcompletestatus() {         alert("setcompletestatus called");     } </script>  @html.checkboxfor(m => m.process.iscomplete,                    new dictionary<string, object>{                      {"id", "p1iscompleted"},                       {"onclick","setcompletestatus()"},                       {"data-role", "flipswitch"},                       {"data-on-text", "complete"},                       {"data-off-text", "incomplete"},                       {"data-wrapper-class", "custom-size-flipswitch"}}) 

this attempt doesn't work:

<script type="text/javascript">     $("#p1iscompleted").click(         function setcompletestatus() {             alert("setcompletestatus called");         }     ); </script> 

this approach leads alert being called once when page loaded not when click on checkbox:

<script type="text/javascript">     $(document).ready(         $("#p1iscompleted").click(             alert("setcompletestatus called");         )     ); </script> 

because of data- attributes cannot use dictionary this: new {@onclick, "setcompletestatus('1')"}

by way, there no javascript errors displayed in firefox's console

you can modify {"onclick", "setcompletestatus()"} code {"onclick","setcompletestatus.call(this)"} , advantage of this variable. should this:

@html.checkboxfor(m => m.process.iscomplete,                   new dictionary<string, object>{                      {"id", "p1iscompleted"},                      {"onclick","setcompletestatus.call(this)"},                      {"data-role", "flipswitch"},                      {"data-on-text", "complete"},                      {"data-off-text", "incomplete"},                      {"data-wrapper-class", "custom-size-flipswitch"}})  <script type="text/javascript">     function setcompletestatus() {         alert(this.checked);     } </script> 

Comments

Popular posts from this blog

c++ - How to add Crypto++ library to Qt project -

php array slice every 2th rule -

My HTML document is not linking to my CSS stylesheet properly -