admin管理员组文章数量:1336380
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;
}
}
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;
}
}
Share
Improve this question
edited Mar 7, 2014 at 19:19
Robbie JW
7391 gold badge9 silver badges22 bronze badges
asked Jan 29, 2013 at 16:16
user2022359user2022359
311 gold badge1 silver badge2 bronze badges
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... – Teemu 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 – user2022359 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... – Teemu Commented Jan 29, 2013 at 16:39
1 Answer
Reset to default 1Use 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);
}
}
本文标签: Iterate through a table using JavaScript to get values of specific cellsStack Overflow
版权声明:本文标题:Iterate through a table using JavaScript to get values of specific cells - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742390886a2465964.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论