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

javascript - Laravel datatable invalid JSON response -

java - Exception in thread "main" org.springframework.context.ApplicationContextException: Unable to start embedded container; -

sql server 2008 - My Sql Code Get An Error Of Msg 245, Level 16, State 1, Line 1 Conversion failed when converting the varchar value '8:45 AM' to data type int -