I'm writing a webpage that uses [what I believe to be] AJAX such that one can enter data into a text field, click an "OK" box, save the data to a database, and re-load the area containing the textfield and "OK" button along with some other data based on the entered data. As it works now, the process works fine on the first entry, but if you try to enter the information again, it behaves as if the original value was entered again:
Example:
User input: 5
Page behaves as if input was: 5
User input: 4
Page behaves as if input was: 5
User input: 3
Page behaves as if input was: 5
When the page initially loads, the area looks like this (yeah, it's blank. I call the code which loads it at the end of the initial loading of the page):
echo "<table>";
// ...Other stuff which I don't think is involved in the problem, though I've been wrong before...
echo "<tr>";
echo "<td>";
echo "<div id=\"measurements\">";
// Filled by javascript functions below
echo "</div>";
echo "</td>";
echo "</tr>";
echo "</table>";
The following javascript function is available and is called when the page loads:
function measurementEntered(pid, vid, oid, varn, dat) {
// Create XMLHttpRequest object
var xmlhttp;
if(window.XMLHttpRequest) {
xmlhttp = new XMLHttpRequest();
}
else {
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.open("GET", "ajax_measurements_update.php?varn="+varn+"&pid="+pid+"&vid="+vid+"&oid="+oid+"&dat"+dat+"&user="+user, false);
xmlhttp.send();
document.getElementById("measurements").innerHTML=xmlhttp.responseText;
}
And the ajax_measurements_update.php page contains the following code to enter the data and refresh the area (there's also some code to add more information to the area, but I don't think it's causing the problem. If you suspect it might, I can post more):
echo "<input type=\"text\" id=\"Select4\" name=\"dat\" size=\"20\" />";
and
echo "<button type=\"button\" onclick=\"measurementEntered($pid, $vid, $oid, $varn, Select4.value);\" />OK</button>";
So this should, upon clicking the "OK" button, pull the data from the "Select4" text field and call the measurementEntered function. The measurementEntered function should then refresh the area with the new "OK" button ready to pull data from the new "Select4" text field. However, when you click it again, measurementEntered is called with the original value from Select4. Any ideas?
Thanks.