Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I copy html elements, then redisplay them with changes?

Status
Not open for further replies.

TroyMcClure

Technical User
Oct 13, 2003
137
US
I have an html table in an IFrame. The table is filled with data fetched from a sql-server database. I want to insert a row in between two existing rows, say, in the middle of the table. The row is hardcoded, so I don't want to refresh the page which would require a trip to the server. I just want to copy the current table, find the row where I want to stick the new one, put the row in, and redisplay the table quickly.

I've seen methods like insertNode, appendChild, but I'm not sure how to use them. Maybe I could just get the outerHTML of the table and put in a string, find the row using string functions, then break apart the string, stick the row in, and put it together that way. The main problem is the redisplay--how is that done?
--T
 
For either class of method - playing with nodes or playing with the HTML strings - update is handled automatically by the browser; there is nothing specific you need to do. Both methods effectively do the same thing when replacing objects; the node method is more efficient for adding new data. Note that a combination of the two is also possible - you could create a new TR node, populate it using its innerHTML method and then insert it into your table at the required position using the insertBefore of insertAfter methods.

The is no 'correct' method - all the methods for altering pages massively overlap in functionality - just use what you feel comfortable with, or what seems easiest to you.
 
MOrac,
Thank you. I'm noticing a discrepancy, though. I did this all via manual parsing of the outerhtml, since I've got to do some adjustments to the actual data within each table row--ie, re-sequencing row numbers, etc.) The row inserts fine, and displays fine after I set the table's .outerHTML. But when I right-click on the page and do View Source, the old stuff is showing--no new row, no resequenced numbers, etc.

Should I be concerned about this? Or is this just because the 'view source' functionality is somehow not hooked into the inner circle of processing and only gets loaded once?
Thanks,
--T
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top