Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4

Thread: type mismatch?

  1. #1
    New Coder
    Join Date
    Jul 2005
    Posts
    33
    Thanks
    0
    Thanked 0 Times in 0 Posts

    type mismatch?

    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


    Code:
    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();
        
        }

  • #2
    New Coder
    Join Date
    Jul 2005
    Posts
    33
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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....

  • #3
    New Coder
    Join Date
    Jul 2005
    Posts
    33
    Thanks
    0
    Thanked 0 Times in 0 Posts
    going abs insane

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

  • #4
    Regular Coder
    Join Date
    Feb 2005
    Posts
    400
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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:
    Code:
      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.
    Last edited by Harry Armadillo; 07-06-2005 at 06:27 AM. Reason: typos


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •