HTML CODE
<div style="width:33%;float:left;">
<span class="label">BodyParts/Muscles</span>
<div id="exerciseFilterList_1"></div>
</div>
<div style="width:33%;float:left;">
<span class="label">Goals (Objective)</span>
<div id="exerciseFilterList_2"></div>
</div>
<div style="width:33%;float:left;">
<span class="label">Device (Tools)</span>
<div id="exerciseFilterList_3"></div>
</div>
<div style="clear:both;"></div>
------------------------------------------------------------------------
JSCODE to fetch data and fill in checkbox
function getExerciseFilter() {
$.getJSON("get_all_exercisefilter.php", function (dataAll) {
$('#exerciseFilterList_1').html(dataAll.filter_bodyParts_view);
$('#exerciseFilterList_2').html(dataAll.filter_goals_view);
$('#exerciseFilterList_3').html(dataAll.filter_tools_view);
});
}
----------
nested checkbox function
//nested checkbox function
$(document).on("change", "input[type='checkbox']", function (e) {
console.log('always');
var checked = $(this).prop("checked"),
container = $(this).parent(),
siblings = container.siblings();
container.find('input[type="checkbox"]').prop({
indeterminate: false,
checked: checked
});
function checkSiblings(el) {
var parent = el.parent().parent(),
all = true;
el.siblings().each(function () {
return all = ($(this).children('input[type="checkbox"]').prop("checked") === checked);
});
if (all && checked) {
parent.children('input[type="checkbox"]').prop({
indeterminate: false,
checked: checked
});
checkSiblings(parent);
} else if (all && !checked) {
parent.children('input[type="checkbox"]').prop("checked", checked);
parent.children('input[type="checkbox"]').prop("indeterminate", (parent.find('input[type="checkbox"]:checked').length > 0));
checkSiblings(parent);
} else {
el.parents("li").children('input[type="checkbox"]').prop({
indeterminate: true,
checked: false
});
}
}
checkSiblings(container);
});
----------
function that fetch data onload
function getEditData(){
$.getJSON("get_exercise_by_id.php?cid=" + cid, function (data) {
data = data[0];
var myfilter = '';
if (typeof (data.filters) != "undefined" && data.filters !== null) {
myfilter = data.filters;
}
if (typeof (myfilter.body_parts) != "undefined" && myfilter.body_parts !== null) {
var pharse_id = ''
for (var body_parts = 0; body_parts < myfilter.body_parts.length; body_parts++) {
pharse_id = '#filter_' + myfilter.body_parts[body_parts];
$(pharse_id).attr('checked', 'checked');
}
}
if (typeof (myfilter.goals) != "undefined" && myfilter.goals !== null) {
var pharse_id = ''
for (var goals = 0; goals < myfilter.goals.length; goals++) {
pharse_id = '#filter_' + myfilter.goals[goals];
$('#filter_' + myfilter.goals[goals]).attr('checked', 'checked');
}
}
if (typeof (myfilter.tools) != "undefined" && myfilter.tools !== null) {
var pharse_id = ''
for (var tools = 0; tools < myfilter.tools.length; tools++) {
pharse_id = '#filter_' + myfilter.tools[tools];
$('#filter_' + myfilter.tools[tools]).attr('checked', 'checked');
}
}
}
----------
data in json coming in this form:
[{"filters":{"body_parts":["1","2","3","4","5","6","7","8","9","10","11","12","13","14","98"
,"99","100","111","112","113"],"goals":["120","121","122"],"tools":["133","134","135"]}}]
----------
I have generated checkbox dynamically which works fine but when I fill data in checkbox on load its not working.Everything works fine on local but on server checkbox not checked onload of getEditdata function.[below are the images of local and server][1]
[1]: http://ift.tt/1VZGXRZ
Aucun commentaire:
Enregistrer un commentaire