keajav
04-05-2006, 10:44 PM
using a table created from an ajax-returned dataset like this:
1 id#1
2 id#2
3 id#3 -> currently editing
i have a textbox that allows a user to move the position of the item "currently editing" by recreating the ajax dataset and rebuilding the table.
the order of the items is then saved to a DB thru another ajax call.
the problem. shifting the items and saving to the DB works find once, but any attempt to save the items again resulst in the javascript code reading the table that was saved previously.
so if i save the table as
1 id#1
2 id#3
3 id#2
and then shift the table to
1 id#3
2 id#1
3 id#2
the javascript function will pick up the order as being stuck as the top one.
i am guessing that my problem is the DOM is not updating, and i need to refresh it, but i cannot use a typical page refresh (ajax constraint). anyone have any advice on this?
code:
function saveItemOrder()
{
var env = getEnv();
var user = getUser();
//read the table for items and order, submit each to ajax call to upd item
var itemId;
var itemOrderNum;
var itemOrderTbl = document.getElementById('tblItemOrder');
var arItemOrder = " ";
for (var i=0; i<itemOrderTbl.rows.length;i++)
{
var iRow = itemOrderTbl.rows[i];
itemId = iRow.id.split("x")[1];
itemOrderNum = itemOrderTbl.rows[i].cells[1].innerHTML;
var itemIdOrderNum = itemId + "|" + itemOrderNum + "|";
if (i != 0)
{
arItemOrder += itemIdOrderNum;
}
else
{
arItemOrder = itemIdOrderNum;
}
}
alert(arItemOrder);
WebPubHome.saveItemOrderwAR(env, user, arItemOrder, callback_saveItemOrder);
1 id#1
2 id#2
3 id#3 -> currently editing
i have a textbox that allows a user to move the position of the item "currently editing" by recreating the ajax dataset and rebuilding the table.
the order of the items is then saved to a DB thru another ajax call.
the problem. shifting the items and saving to the DB works find once, but any attempt to save the items again resulst in the javascript code reading the table that was saved previously.
so if i save the table as
1 id#1
2 id#3
3 id#2
and then shift the table to
1 id#3
2 id#1
3 id#2
the javascript function will pick up the order as being stuck as the top one.
i am guessing that my problem is the DOM is not updating, and i need to refresh it, but i cannot use a typical page refresh (ajax constraint). anyone have any advice on this?
code:
function saveItemOrder()
{
var env = getEnv();
var user = getUser();
//read the table for items and order, submit each to ajax call to upd item
var itemId;
var itemOrderNum;
var itemOrderTbl = document.getElementById('tblItemOrder');
var arItemOrder = " ";
for (var i=0; i<itemOrderTbl.rows.length;i++)
{
var iRow = itemOrderTbl.rows[i];
itemId = iRow.id.split("x")[1];
itemOrderNum = itemOrderTbl.rows[i].cells[1].innerHTML;
var itemIdOrderNum = itemId + "|" + itemOrderNum + "|";
if (i != 0)
{
arItemOrder += itemIdOrderNum;
}
else
{
arItemOrder = itemIdOrderNum;
}
}
alert(arItemOrder);
WebPubHome.saveItemOrderwAR(env, user, arItemOrder, callback_saveItemOrder);