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 Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Deleting Table Rows not working in Firefox

Status
Not open for further replies.

okiiyama

IS-IT--Management
Joined
Jan 3, 2003
Messages
269
Location
US
My code visually works fine in IE, but it may be hanging up in Firefox. I checked the js console, and I am not getting an error. What my code is doing is looping through table rows, and finding a nested childnode with a name of "bottom_img_lnav". Once it finds that nested childnode it then starts to delete the rows after, and stops when there are no more rows to delete. Is there a better way to do this that could be compatible with both IE and FF?

Code:
var hitBottomIMG = false;
for(var i = 0; i<ta1.rows.length; i++) {
 if(ta1.rows[i].childNodes[0].childNodes[0] != null
     && ta1.rows[i].childNodes[0].childNodes[0].name == "bottom_img_lnav") {
        hitBottomIMG = true;
  } else if(hitBottomIMG) {
        ta1.deleteRow(i);
  }
}
_
 
I'd say you need to decrement i when you delete a row... but also update your loop end condition...

Basically, you can't use a for loop - you'll have to use a while loop.

Hope this helps,
Dan



Coedit Limited - Delivering standards compliant, accessible web solutions

[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
I thought about that, because its strange to use a check that is being decremented because of deleteRow() and so I tried an implementation of starting from array.length -1 and working backwards, and I beleive it did work in FF, but then not entirely in IE.

What seems strange is that all the functions that I'm testing outside of any sort of loop work in both IE and FF, but when looping, for some reason doesn't work. I've eliminated the for loop and switched to a while loop that will loop until it hits the nested element with the name "bottom_img_lnav" or will stop when the index >= arrayLength. This loop right now is to get the index of the row that contains the nested element I'm search for. In ie it works, but in FF it doesn't..

Code:
	var hitBottomIMG = false;
	var endOfArray = false;
	var rowIndex = 0;
	
	while(!hitBottomIMG && !endOfArray) {
		var el = ta1.rows[rowIndex];
		if(el != null) {
			var elChild = el.firstChild;
			if(elChild != null) {
				var elChildChild = elChild.firstChild;
				if(elChildChild != null) {
					if(elChildChild.name == 'bottom_img_lnav' ) {
						hitBottomIMG = true;
					}
				}
			}
		} 
		rowIndex++;
		if(rowIndex >= ta1.rows.length) {
			endOfArray = true;
		}
	}
	
	if(endOfArray && !hitBottomIMG) {
		alert("Did Not Find Bottom Image");
	} else if(hitBottomIMG) {
		alert("Found Bottom Image");
	}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top