Forum Moderators: open

Message Too Old, No Replies

Updating Multiple Rows / Stock Type Prices

         

Frank_Rizzo

11:09 am on Nov 12, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



What's the best way to update a page of stock type prices?

I have ajax code which retrieves a text string from the server in the following format:

row1,100
row2,150
row3,80
.
.
rowX,nnn

The html page has a simple table:

Widget Type Price
-----------------
Green Widgets 100
Blue Widgets 150
Red Widgets 80
.
.
X Widgets nnn

The widgets text is static but I need to update just the Price column.

I guess I just need many divs in there with ids from 1 to x?

Second question: How do I get the page to retrieve prices every 60 seconds?

Frank_Rizzo

3:44 pm on Nov 13, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I managed to work this out. All I had to do was use getElementById('widgets'+ counter

I'll leave out the meat of the ajax stuff. Below is the process response routine which builds the data for displaying.

Assume the server php file returns a text string of

110¦85¦203


function processResponse() {
if(http.readyState == 4){
var response = http.responseText;
if(response.indexOf('¦'!= -1)) {
var update = response.split('¦');
for (var i = 0; i < update.length; i++)
document.getElementById('widgets'+i).innerHTML = update[i];

}

}

}

.
.
.

<p><a href="javascript:makeGetRequest(1)">Update Prices</a></p>
Green Widgets <div id='widgets0'></div>
Blue Widgets <div id='widgets1'></div>
Red Widgets <div id='widgets2'></div>