3

How can I iterate through a table using JavaScript to get the values of cells 4 and 5?

This is what I have:

function constructString() {    
    var table=document.getElementById('wcList');

    for(var i=0; i<table.rows.length;i++){

        var row       = getElem(RowId + i);
        var str_wc    = table.rows[i].cells[1].firstChild.value;
        var str_act   = table.rows[i].cells[5].firstChild.value;
        var str_coh   = table.rows[i].cells[6].firstChild.value;
        var str_mconf = table.rows[i].cells[7].firstChild.value;

        var string1 = str_wc + row + str_act + row + str_coh + row + str_mconf + row;

     }
}
3
  • 1
    getElem() is not native JS or DOM function, what does it do? Also a small snippet of the HTML code would be helpful... Commented Jan 29, 2013 at 16:18
  • working in sap mii so the page is displayed in xsl. Display table allow user to select 1 or several row and update columns 5, 6, 7 then click save button. need to Loop through all edited rows and build a string of concatenated values. Then Create a BLS (updateWCData) which takes the above created string as a input Commented Jan 29, 2013 at 16:34
  • Please show us one row of the table, so we don't need to guess how you can get the content you want. Just help us to help you... Commented Jan 29, 2013 at 16:39

1 Answer 1

1

Use innerHTML.

Try this:

function constructString() {   
    var table=document.getElementById('wcList');

    for(var i=0; i<table.rows.length;i++){

        // FIX THIS
        var row = 0;

        var str_wc=(table.rows[i].cells[1].innerHTML);
        var str_act=(table.rows[i].cells[5].innerHTML);
        var str_coh=(table.rows[i].cells[6].innerHTML);
        var str_mconf=(table.rows[i].cells[7].innerHTML);

        var string1=str_wc +row+str_act+row+str_coh+row+str_mconf+row;

        alert(string1);
     }
}  
Sign up to request clarification or add additional context in comments.

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.