L
libsfan01
Hi all
Im trying to write a script that pulls data from another page (which is
getting data from a db). The contents displayed on the db handling page
(display.php) gets transferred through XMLHttpRequest continuously,
however when setting the value using getElementById the value of the
element is not being replaced, it is being appended each time.
Here is my code, how can i modify the code to replace the contents of
the element (showmsgs) each time data is requested and sent from the db
handling page (display.php):
<html>
<head>
<script type="text/javascript">
var get; //object to get from db
var data; //contents of response
function getdata() {
get = new XMLHttpRequest();
get.onreadystatechange = processdata;
get.open("GET", "display.php");
get.send(null);
}
function processdata() {
if (get.readyState == 4) {
data = get.responseText;
document.getElementById("showmsgs").value = data;
getdata();
}
}
</script>
</head>
<body>
<input type="button" value="button" onClick="getdata()"><br>
<textarea id="showmsgs">
</textarea>
</body>
</html>
Thanks
Marc
Im trying to write a script that pulls data from another page (which is
getting data from a db). The contents displayed on the db handling page
(display.php) gets transferred through XMLHttpRequest continuously,
however when setting the value using getElementById the value of the
element is not being replaced, it is being appended each time.
Here is my code, how can i modify the code to replace the contents of
the element (showmsgs) each time data is requested and sent from the db
handling page (display.php):
<html>
<head>
<script type="text/javascript">
var get; //object to get from db
var data; //contents of response
function getdata() {
get = new XMLHttpRequest();
get.onreadystatechange = processdata;
get.open("GET", "display.php");
get.send(null);
}
function processdata() {
if (get.readyState == 4) {
data = get.responseText;
document.getElementById("showmsgs").value = data;
getdata();
}
}
</script>
</head>
<body>
<input type="button" value="button" onClick="getdata()"><br>
<textarea id="showmsgs">
</textarea>
</body>
</html>
Thanks
Marc