jeudi 26 novembre 2015

How to get checkbox value when checked and pass it to controller

I have some check boxes and want to pass their values (value=1)to controller when they checked, if not checked just leave it null.

HTML:

<div  class="col-md-7">
  <div class="checkbox-list" style="padding-top: 8px;">
    <input name="add_content" id="add_content" value="1" type="checkbox" /> 
    <input name="edit_content" id= "edit_content" value="1" type="checkbox" /> 
   </div>
 </div>

JQuery Code:

        save: function () {

        var self = this;
        var id = $("#in_id").val();

        var add_content = $("[add_content='add_content']").val();
        var edit_content = $("[edit_content='edit_content']").val();

        KeyWord.updateUser(id, add_content, edit_content,delete_content,manage_user,view_log,
            function (data) {
                alert("data saved succesfully.");

            },
            function (error) {
                jqXhrErr(error);
            });
    }

var KeyWord = function () {

var url_update = "api/user/Update";


return {

    updateUser: function (id, add_content, edit_content, done, fail, always)  {
        var jqxhr = $.post(url_update, { id: id, add_content: add_content, edit_content: edit_content});
        return jqXhrHandler(jqxhr, done, fail, always);
    }

}
}();

The problem is that, controller only get non-checkbox value but it does not receive checkbox value when they check?

any error here?




Aucun commentaire:

Enregistrer un commentaire