c# - Editorfor checkbox field onclick -


i have editorfor field checkbox , when changed false true , form submitted need track checkbox changed , marked true. has javascript or jquery function.

<div class="editor-field"> @html.editorfor(model => model.ispublic)  </div>  

if need explain better please tell me. cant think of how else explain.thanks

hope following code it:

@html.hiddenfor(model => model.ispublicchanged) @*create special model field handling change event*@  $().ready(function () {             //catch change event , assign value hidden field     $("input[name=ispublic]").on("change", function () {         $("input[name=ispublicchanged]").val('true');     }); }); 

or different js-code if want see if value of checkbox changed comparing it's initial value:

$().ready(function () {     var trackvalue = $("input[name=ispublic]").prop("checked");      $("form").on("submit", function () {         var actualvalue = $("input[name=ispublic]").prop("checked");         if (actualvalue != trackvalue) {             $("input[name=ispublicchanged]").val('true');         }     });      }); 

Comments

Popular posts from this blog

wireshark - USB mapping with python -

c++ - nodejs socket.io closes connection before upgrading to websocket -

Deploying Qt Application on Android is really slow? -