Forum Moderators: coopster

Message Too Old, No Replies

updation by ajax

cant able to get new values after changed at another page at onclick button

         

waqar100

6:59 pm on Sep 21, 2009 (gmt 0)

10+ Year Member



I am new in php

problem is that ,i have a table having 3 coloums ,id,firstname,lastname,
& 3 textboxes

1st at page fetch.php user give an id & after submitting the values of the row are retrieved at the 3 textboxes.
,now I want to update by changing the values of Tboxes.

here is a code of page fetch.php.

<script language="javascript" type="text/javascript">
var httpobject=null;
function call(x,y,z)
{
//document.write(x,y,z);
httpobject=getHTTPObject();
if(httpobject!=null)
{

var url=("up.php?x="+x+"&y="+y+"&z="+z);
//document.write(url);

httpobject.open("GET", url ,true);
httpobject.send(null)
httpobject.onreadystatechange=setoutput;

}
}
function setoutput()
{
if(httpobject.readystate==4)
{

document.write(httpobject.responseText);
}
}

function getHTTPObject()
{
if (window.ActiveXObject)
{return new ActiveXObject("Microsoft.XMLHTTP");}
else
{
alert("Your browser does not support AJAX.");
return null;
}}


</script>

<?php
....
...
...
....
....here is the retrieving code which take an id # & give the records in below textboxes,from there i want to getting the values at up.php

....
.....
....

echo "<input type='text' name='one' value= '$aaa'/>";
echo "<input type='text' name='y' value= '$aa' />";
echo "<input type='text' name='z' value= '$bb'/>";
echo "<input type='button' onclick=\"call($aaa,'$aa','$bb')\" value= 'updatenow' />";

problem is that i cant able to get the new values of textboxes after changing in textboxes, i am getting the old values .

what is the problem here?

IanKelley

8:35 pm on Sep 21, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



This is just a guess after skimming your code, hard to be sure without seeing all of it so I might be missing something...

It seems your JS takes the user input and sends it to up.php via a GET request, yes?

However your <form> is still getting submitted and is sending the old values to up.php via a POST request. The GET request happens first, however it is then followed by the POST request which essentially overwrites it. The user is taken to up.php via the POST request and therefore sees the old values.

If this is the case then AJAX isn't really needed in this instance, just have the user submit the form with the updated values as normal.

waqar100

6:44 am on Sep 22, 2009 (gmt 0)

10+ Year Member



no i got it ,i think i should have to post complete coding
thank you

function call()
{
var x=document.getElementById("one").value;
var y=document.getElementById("y").value;
var z=document.getElementById("z").value;
}

echo "<input type='button' onclick=\"call()\" value= 'updatenow' />";

it was the error ,i was not taking the values from JS.