I have some checkboxes and want to pass their values (value=1
) to a controller when they are checked, if not checked just leave it null
.
<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>
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 the controller only gets non-checkbox value but it does not receive checkbox value when they check?
Any error here?