Hello! I have written this test code:
Code:
<html>
<body>
<script type="text/javascript">
function ajaxFunction() {
var xmlHttp;
try { //Firefox, Opera 8.0+, Safari
xmlHttp = new XMLHttpRequest();
}
catch (e) {
try {
xmlHttp = new ActiveXObject("MSXML2.XMLHTTP.3.0");
}
catch (e) {
alert("Your browser does not support AJAX!");
return false;
}
}
xmlHttp.onreadystatechange = function() {
if(xmlHttp.readyState==4) {
document.myForm.time.value = xmlHttp.responseText;
xmlHttp.responseText = "";
}
}
xmlHttp.open("get","time.php",true);
xmlHttp.send(null);
}
</script>
<form name="myForm">
Name: <input type="text" onkeyup="ajaxFunction();" name="username" />
Time: <input type="text" name="time" />
</form>
</body>
</html>
And in time.php:
Code:
<?php
echo date("H:i:s");
?>
And it works, I'm actually surprised.
But what doesn’t surprise me is that the function of getting the time to the textbox only works once; the first time I release a key when the left textbox is marked the current time pops up in the right textbox, but the rest of the times (after clearing the textboxes), the same text as before will pop up again, which is the old time and not the current time!
I would really appreciate some help here. Surprise me!