0

how to insert values in a html table, an array multidimensional in javascript.

Additionally, such as performing calculations between the columns of the array and insert the results into a column of the same array.

thanks for your answers.

4
  • Are you talking about adding two arrays? As in c[i] = a[i] + b[i];? Commented Jul 29, 2010 at 22:13
  • I can't make enough sense of this question to edit it into something more comprehensible... did you use a translator for this? Of course, that's not a problem but it might be a good idea to give it another go. Commented Jul 29, 2010 at 22:16
  • multimencional, did you mean multidimensional? How to insert values from an html table into a multidimensional array in javascript? Commented Jul 29, 2010 at 22:17
  • I'm sorry. You did not phrase your question in the form of a question. Commented Jul 29, 2010 at 22:23

2 Answers 2

2

Javascript code:

var multiArray;
window.onload = function() {
    // load the table into the multidimensional array.
    multiArray = [];
    var trs = document.getElementsByTagName('TR');
    for(var i = 0; i < trs.length; i++) {
        var arr = [];
        var tds = trs[i].childNodes;
        for(var j = 0; j < tds.length; j++) {
            var td = tds[j];
            if (td.tagName === 'TD') {
                arr.push(td.innerHTML);
            }
        }
        multiArray.push(arr);
    }
    // perform some calculations between the columns of the array
    var resCalc = [];
    for(i = 0; i < multiArray.length; i++) {
        resCalc[i] = 0;
        for(j = 0; j < multiArray[i].length; j++) {
            resCalc[i] += multiArray[i][j];
        }
    }
    // insert the results into a column of the same array
    var columnToModify = 0; // the index of the column you want to change
    for(i = 0; i < multiArray.length; i++) {
        multiArray[i][columnToModify] = resCalc[i];
    }
};
Sign up to request clarification or add additional context in comments.

Comments

0

something on Google…

http://www.eggheadcafe.com/community/aspnet/3/10003047/html-table-in-to-an-array.aspx

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.