View Full Version : count number of text elements

05-07-2006, 10:48 PM
I am using AJAX to load data that changes every few seconds. The AJAX works fine, but the way I'm trying to get the data to update is by having the AJAX send the latest timestamp to the data.php page.

The php page returns the data with a hidden text box, that contains the latest timestamp. HOWEVER, I need a way for the javascript to determine what the latest text box was because in the <div> there will be more than just one since the data will be appended to the <div>.

The main page:

//AJAX script is above here
function getData(){
//tmp = latest timestamp..???

request.open('get', 'data.php?time='+tmp);
document.getElementById('showData').innerHTML += ajax_return;
<div id=showData>
updated data goes here from data.php

Then data.php

$sql = mysql_query("SELECT * FROM data WHERE timestamp >= '{$_GET['time']}'");
while($row = mysql_fetch_array($sql)){

$latest_time = time();
echo $row['data'];
echo "<input type=hidden name=timestamp id=timestamp[] value=\"".$latest_time."\">";

I hope I explained it right lol. The code above are only examples of what I'm trying to do.
In summary, I guess what I'm trying to do is count the number of inputs there are, and extract the value from the last, or highest element when it is created.
Thanks in advance:)