Hello experts,i am trying to make an update panel with ajax and php.The primary purpose is updating the data that has pullen from mysql and parsed in table.I wrote a loop that creates forms and input fields and attaches the value that has pullen from DB as the value of input field,and named the field as id.With onblur key event the reform() function sends the id (the name of the fields) to update.php via AJAX. Every thing works fine for the first variable (that belongs to the first row of the table).But it doesnt work for rest of the rows.. Any comments will be appriciated..
<script type='text/javascript'>
function reform()
{
xmlHttp=ajax();
if (xmlHttp==null)
{
alert ('Your Browser doesnt suppot ajax!');
return;
}
var id = document.getElementById('i
d').value;
var url='update.php';
var sc ='id='+id ;
xmlHttp.open('POST', url, true);
xmlHttp.setRequestHeader('
If-Modifie
d-Since', 'Sat, 1 Jan 2000 00:00:00 GMT');
xmlHttp.setRequestHeader('
Content-Ty
pe','appli
cation/x-w
ww-form-ur
lencoded; charset=UTF-8');
xmlHttp.setRequestHeader('
Content-le
ngth', sc.length);
xmlHttp.setRequestHeader('
Connection
', 'close');
xmlHttp.onreadystatechange
=update;
xmlHttp.send(sc);
}
function update()
{
if (xmlHttp.readyState==4 && xmlHttp.status == 200)
{
document.getElementById('r
esult').in
nerHTML=xm
lHttp.resp
onseText;
}
}
function ajax()
{
var xmlHttp=null;
try
{
// Firefox, Opera 8.0+, Safari
xmlHttp=new XMLHttpRequest();
}
catch (e)
{
// Internet Explorer
try
{
xmlHttp=new ActiveXObject('Msxml2.XMLH
TTP');
}
catch (e)
{
xmlHttp=new ActiveXObject('Microsoft.X
MLHTTP');
}
}
return xmlHttp;
}
</script>
Start Free Trial