473,387 Members | 1,693 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Deleting rows in a table in HTML page containing data from XML

cameokid
Hi,

Here is the problem which i am facing. I am trying to delete rows (using nodes) containing XML data. I am doing this to add new set of data from XML file by using a dropdown selection.

I am using the below code.(This is just a part of the code)

Expand|Select|Wrap|Line Numbers
  1. tab = document.getElementById('maintable').getElementsByTagName("tbody")[0];
  2. for(i=0;i<tab.childNodes.length;i++) {
  3. tab.removeChild(tab.childNodes[i]);
  4. }
  5.  
tab.childNodes refers to all the <tr> tags. Though i am referring to all the rows in the loop, i am able to delete only alternate rows in the table in IE and the other alternate rows get deleted in firefox.

I need to delete all the rows. Can someone help me out with this?
Apr 1 '08 #1
2 1421
pronerd
392 Expert 256MB
I think you may just need to reverse your loop.

Since object oriented code works by just passing a reffernce to the object you are alwaysing working with just one instance of an object, no matter how many of them you make. I think your code is removing a row, which then causes all the rows in the array to be reordered.

So if you for instance have a list or an array with four elements....

[0], [1], [2], [3]

and you remove its items one at a time. Your loop will remove the first item (index 0). Leaving you with .....

[0], [1], [2]

Then your loops moves up to index 1 which is now actually the second item in the array. Leaving you with ....

[0], [2]



So if you reverse your loop and remove them from the end you should get around this problem.

Expand|Select|Wrap|Line Numbers
  1.     tab = document.getElementById('maintable').getElementsByTagName("tbody")[0];
  2.     for(i=tab.childNodes.length; i>0; i++) {
  3.         tab.removeChild(tab.childNodes[i]);
  4.     }
  5.  
Apr 1 '08 #2
Yeah that's great.

It works fine when you delete in the reverse order.

Thank you.
Apr 2 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Jim Heavey | last post by:
Trying to figure out the technique which should be used to add rows to a datagrid. I am thinking that I would want an "Add" button on the footer, but I am not quite sure how to do that. Is that...
2
by: Zak McGregor | last post by:
Hi all I have a table, for simplicity's sake containing one field, called unid. for example, select unid, oid from table gives me something like this: unid | oid ---------+---------
12
by: bikkaran | last post by:
Hi , I have a table that contains 15lakh records..... I want delete that table....and insert fresh set of record. when I run the command ...db2 "delete from schema.tabname" it hangs...
2
by: Muzzy | last post by:
Hi, I've used information on these newsgroups to build many pages. So I thought that now that I have my script working (something that I've been working on for about a week), I should post it so...
7
by: Susan Mackay | last post by:
I have a data table that is connected to a database table with a data adapter in the 'standard' manner. However I want to be able to remove selected rows from the data table (i.e. no longer...
1
by: Fix_Metal | last post by:
Hello all. I'm new to this group :) I have a problem with javascript language. I'm making an .asp page with some integrated Javascript functions. The page consists of some HTML selects and a...
1
by: serge | last post by:
IF (SELECT OBJECT_ID('t1')) IS NOT NULL DROP TABLE t1 GO CREATE TABLE t1 (c1 INT, c2 INT) DECLARE @n INT SET @n = 1 WHILE @n <= 454 BEGIN INSERT INTO t1 VALUES (@n, @n)
5
flexsingh
by: flexsingh | last post by:
Hello there, I have been trying to delete a row in php for a long time now and its getting frustrating, can any see if they could possible help me please. My first page is <?php // this...
3
by: nigelesquire | last post by:
Please help! I'm trying to clone and delete multiple rows with JavaScript. I need two delete buttons that work...! I only have one for now, but it's not working properly, the output count is...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.