i want to checkde the checkbox if its value is found in the database. for that i have two array one is checkbox array and another is result of database so, compare both and when match is found then checkde the checkbox.
$('body').on('click','.update', function(){
var edit_id = $(this).attr('id');
var a=[];
var b=[];
$.ajax({
type: 'POST',
url: 'update.php',
data: 'edit_id='+edit_id,
success: function(data) {
var a=data.split(",");
$("#up").val(a[0]);
$("#title1").val(a[1]);
$("#prod").val(a[2]);
$("#dir").val(a[3]);
$("#wri").val(a[4]);
var c = (a[5]);
var b=c.split(".");
var g=document.getElementsByName("genre[]");
for(var i=0;i<g.length;i++)
{
var t=document.getElementsByName("genre[]")[i].value;
document.getElementsByName("genre[]")[i].checked=false ;
if(t[i]=b[i])
{
document.getElementsByName("genre[]")[i].checked=true ;
//$(t[i]).prop("checked", true);
}
}
//rowElement.add("<tr>" + data + "</tr>");
//$('#chatbox table tr:last').after("<tr>" + data + "</tr>");
if (data = "true") {
// $("#title1").val(data);
alert("update "+data);
}
else {
alert("not update");
alert("update"+data[0]);
}
}
});
});
Aucun commentaire:
Enregistrer un commentaire