...

View Full Version : type mismatch?



khan8822
07-05-2005, 07:54 PM
table.tBodies[0].appendChild(newRows[i]);

does anyone know why this statement would cause

type mismatch on IE?

infoRows are rows that are not put into sort consideration

it works fine when i have no info rows



var firstRow = new Array();
var newRows = new Array();

var infoRows = new Array();

for (i=0; i<table.rows[0].length; i++) { firstRow[i] = table.rows[0][i]; }

//for (j=1; j < table.rows.length; j++) { newRows[j-1] = table.rows[j]; }
for (j=1; j < table.rows.length; j++)
{

//alert(table.rows[j].id);

if(table.rows[j].id.indexOf('M') != -1)
{
newRows[j-1] = table.rows[j];
//alert(table.rows[j].id);
}
else
{
infoRows[j-1] = table.rows[j];
}

}

newRows.sort(sortfn);



for(i=0; i < newRows.length; i++)
{
table.tBodies[0].appendChild(newRows[i]);

//alert();

}

khan8822
07-05-2005, 08:24 PM
for some reason if i add

alert(newRows.length);

right before the last for loop

it print out 4 the first time i try to sort it

and 3 after the first sort........

there are suppose to be only 3 element to be sorted....

khan8822
07-05-2005, 09:05 PM
going abs insane

how could it return different number of rows?!?!??

Harry Armadillo
07-06-2005, 05:17 AM
When you load your table rows in the newRows array, the index number are not continuous. IE is complaining because you are giving appendChild nulls/undefineds, since newRows[i] doesn't alway contain a row.

Let say, table rows 1,3 and 5 have the extra-special M-containing id. That mean your newRows array uses the index numbers 0, 2, and 4. But what about index 1 and 3? Does your sort function know how to deal with non-existing array members? When you get the length property, are you expect 3 because you put in three rows, or 5 because you have things in the 0 through 4 range?

Try:
if (table.rows[j].id.indexOf('M') != - 1) {
newRows[newRows.length] = table.rows[j];
//alert(table.rows[j].id);
}
else {
infoRows[infoRows.length] = table.rows[j];
}
}that'll save you from the horrors of skipped index numbers.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum