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
  1. #1
    New Coder
    Join Date
    Nov 2006
    Posts
    15
    Thanks
    0
    Thanked 0 Times in 0 Posts

    looping through dom elements

    hi,

    i'm trying to loop through a table to find the next row with empty td elements. i've put alert events along the way to try and debug it (normally i'd have (txt=='') in the if control structure.

    the first alert popup says [object text], the second says undefined. how do i change the code so nextEmptyRow reads the next empty row's index or id?

    Code:
    insRow:function(elm){
    	  var tbl = elm.parentNode;
    	  for (var i=0;i<tbl.rows.length;i++) {
    	    var currTr = tbl.rows[i];
    		var td = currTr.firstChild;
    		var txt = td.firstChild;
    		alert(td);
    	    if (txt == '3'){
    		  var nextEmptyRow = '3';
    		  break;
    		}
    	  }
    	  alert(nextEmptyRow);

  • #2
    Senior Coder whizard's Avatar
    Join Date
    Jan 2005
    Location
    Philadelphia, PA, USA
    Posts
    1,662
    Thanks
    14
    Thanked 76 Times in 76 Posts
    I'm not sure I can be helpful here, but does is this pages helpful to you at all?

    http://dojotoolkit.org/pipermail/doj...ly/011832.html

    Dan
    PHP Tip: If you want to use short tags (<? or <?=$var) then make sure short_open_tag is set to "1". It really helps.

    Don't forget to save everyone time and mark your thread as Resolved :)

    "Also note that it is your responsibility to die() if necessary."

    DON'T USE THE MYSQL_ EXTENSION

  • #3
    Senior Coder Arbitrator's Avatar
    Join Date
    Mar 2006
    Location
    Splendora, Texas, United States of America
    Posts
    3,305
    Thanks
    28
    Thanked 276 Times in 270 Posts
    Why don’t you just put the alert inside the if statement? If you necessarily need to keep it outside of the if statement though, you can declare nextEmptyRow outside of the for statement instead of inside it so that the alert function can access it.
    For every complex problem, there is an answer that is clear, simple, and wrong.

  • #4
    New Coder
    Join Date
    Dec 2006
    Posts
    38
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hrm, i dont think i understand what youre doing in your code, i mean i understand your problem but not the way youre going at it.

    You want to find the first TD element inside a table that is empty? Or the first row that has an empty TD element? either ways this could probably help you:

    Code:
    insRow:function(elm){
    
    var table = elm.parentNode
    var i, td, currTr, nextEmptyRow;
    for(i = 0; i < table.rows.length; i++) {
      currTr = tbl.rows[i];
      td = currTr.firstChild;
      if (!td.childNodes.length){
    
        /* no children found set nextEmptyRow to the id of the 
         * empty td
         */
    
        nextEmptyRow = td.id;
        break;
      }
    }
    alert(nextEmptyRow);
    }
    http://demo.vegui.org - vegUI AJAX framework
    http://www.landsofkazram.com - browser based graphical MMORPG


  •  

    Posting Permissions

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