change checkbox value using ajax

I was working on jqgrid changing the status 0 and 1 in database by checking the the checkbox in grid.Problem i faced was as check the checkbox it update value through ajax,but it doesnt change value in checkbox for it needed to refresh the page.What i did is got response of status through ajax and change value of checkbox using

                     var checkbox = $( "#"+status_id );
var ns = checkbox.val( checkbox[0].checked ? "1" : "0" );

i was getting the checkbox as json from php In which you can find example in jqgrid with php.


sample code passed through json:


<input type='checkbox' name='status'  id='status_".$temp."'  value='0' onchange='pathwaystatus($temp)' />

function to change status:


function pathwaystatus(e)
{
//alert(e);
var status_id = "status_"+e;
//alert(status_id);
var chkbxval = document.getElementById(status_id).value;
//alert(chkbxval);
var xmlHttp = getXMLHttp();
xmlHttp.onreadystatechange = function()
{
if(xmlHttp.readyState == 4)
{
var res = HandleResponse1(xmlHttp.responseText);
alert(res);
var checkbox = $( "#"+status_id );
var ns = checkbox.val( checkbox[0].checked ? "1" : "0" );
alert(ns);
}
}
xmlHttp.open("GET", "pathwaystatus.php?chkbxval="+chkbxval+"&id="+e, true);
xmlHttp.send(null);
}

Comments

Popular posts from this blog

create pdf by using javascript

yii framework simple shopping cart tutorial for beginners

yii2 arrayhelper::map vs array_map