www.webdeveloper.com
Results 1 to 6 of 6

Thread: javascript table

  1. #1
    Join Date
    Mar 2011
    Posts
    7

    Unhappy javascript table

    hello!

    i'll go straight to the point, i have 8 rows and 3 columns, i want to populate each <td> starting from:
    row 0 column 0 a value of 1
    row 0 column 1 a value of 2
    row 0 column 2 a value of 3
    row 1 column 0 a value of 4
    row 1 column 1 a value of 5
    ...
    row 7 column 2 a value of 24

    also if i choose say row 2 column 2 as starting point the rest of the <td>'s before it will not contain any value...

    any help from the experts is really appreciated!

  2. #2
    Join Date
    Dec 2003
    Location
    Bucharest, ROMANIA
    Posts
    15,428

  3. #3
    Join Date
    Jan 2010
    Location
    Winnipeg, Manitoba, Canada
    Posts
    95
    Sorry, but try to see if there's anything different in the error area. I could help more, but I need to see your code.

  4. #4
    Join Date
    Mar 2011
    Posts
    7
    Quote Originally Posted by njaohnt View Post
    Sorry, but try to see if there's anything different in the error area. I could help more, but I need to see your code.
    sorry, here's the code, hope it helps....

    <script type="text/javascript">
    function popIt() {
    var t = document.getElementById('tblVisaStk').rows;
    //var t = document.getElementById('tblVisaStk');
    var k = getCookie('matrix'); // starting point set in a separate file e.g R2C1
    var r = k[1]; // get coordinates only
    var c = k[3];
    var col;
    for(i = r; i < 8; i++) {
    //if (c == 1) { col = 0; } else if (c == 2) { col = 2; } else { col = 0; }
    for (j = c; j < 3; j++) {
    if (i == r) { j++; }
    //if (k == 'R'+i+'C'+j) { // disabled this temporarily
    var y = t[i].cells;
    y[j].innerHTML = i+j; // i can't get it to work
    //}
    /*var oCell = t.rows(i).cells(j);
    oCell.innerHTML = 'test';*/
    }
    }
    /*var oTable = document.getElementById("tblVisaStk");
    var oCell = oTable.rows(2).cells(1);
    oCell.innerHTML = 'test';*/
    }
    </script>

    any violent reactions are welcome!

  5. #5
    Join Date
    Mar 2011
    Posts
    7

    Wink

    Quote Originally Posted by corics15 View Post
    sorry, here's the code, hope it helps....

    <script type="text/javascript">
    function popIt() {
    var t = document.getElementById('tblVisaStk').rows;
    //var t = document.getElementById('tblVisaStk');
    var k = getCookie('matrix'); // starting point set in a separate file e.g R2C1
    var r = k[1]; // get coordinates only
    var c = k[3];
    var col;
    for(i = r; i < 8; i++) {
    //if (c == 1) { col = 0; } else if (c == 2) { col = 2; } else { col = 0; }
    for (j = c; j < 3; j++) {
    if (i == r) { j++; }
    //if (k == 'R'+i+'C'+j) { // disabled this temporarily
    var y = t[i].cells;
    y[j].innerHTML = i+j; // i can't get it to work
    //}
    /*var oCell = t.rows(i).cells(j);
    oCell.innerHTML = 'test';*/
    }
    }
    /*var oTable = document.getElementById("tblVisaStk");
    var oCell = oTable.rows(2).cells(1);
    oCell.innerHTML = 'test';*/
    }
    </script>

    any violent reactions are welcome!
    just got it to work! thank you!

    Code:
    <script type="text/javascript">
    	function popIt() {
    		var t = document.getElementById('tblVisaStk');
    		var k = getCookie('matrix'); // starting point, set in a different file
    		var r = k[1]; // e.g. from R2C1, extract coordinates row 2
    		var c = k[3]; // column 1
    		var cnt = 0;
    		for(var i = 0; i < 8; i++) {
    			for (var j = 0; j < 3; j++) {
    				t.rows[i].cells[j].appendChild(document.createTextNode((i < r || (i == r && j < c))? '' : cnt++));
    			}
    		}
    	}
    </script>

  6. #6
    Join Date
    Jan 2010
    Location
    Winnipeg, Manitoba, Canada
    Posts
    95
    huh

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles