I have a table on a form that is formatted like this:
<table id='leaderTable'>
<tbody>
<tr>
<td> Name1</td><td> item1</td><td> item2</td> <td> item3</td><td> item4</td><td> item5</td>
</tr>
<tr>
<td> Name2</td> <td> item1</td> <td> item2</td><td> item3</td><td> item4</td><td> item5</td>
</tr>
<tr>
<td> Name3</td>
-- etc. --
I search for and find a given Name in col-1 of this table, extract the data from cells to the right of that found Name, and copy them to a list in a textArea (id=leaderInfoArea).
Then I want to edit this text and copy it back to the original table, replacing the old data.
I've got the first part working and can extract the data to the textArea, but now I'm stuck and I don't know how to get it back to the table.
Here's how I'm extracting each record from the html table.
function getLeaderData() { // match the Pod Leader's entered name on the form (leaderName) against each cell in col-1 of leaderTable
let leaderInfoArea = document.getElementById('leaderInfoArea') ;
let leaderName = document.getElementById('leaderName').value.trim();
leaderName = leaderName.toLowerCase();
leaderName = leaderName.replace( '.' , ' ').replace(/ +/g, ' ');
let tab = document.getElementById('leaderTable');
let tabRows = tab.rows;
for (let i = 0; i < tabRows.length; i++) {
let leaderNameCell = tabRows[i].cells[0];
let nextLeaderName = leaderNameCell.innerText.trim();
nextLeaderName = nextLeaderName.toLowerCase();
nextLeaderName = nextLeaderName.replace.( '.' , ' ').replace(/ +/g, ' ');
if (leaderName === nextLeaderName) { // if the names match, copy the data for this Pod Leader into leaderInfoArea, and exit
leaderInfoArea.value = "";
for (let j = 0; j < tabRows[i].cells.length; j++) {
leaderInfoArea.value += tabRows[i].cells[j].innerText + "\r";
}
return;
}
}
}
leaderInfoArea now contains a list 6 lines high, although I can't get this editor to show that.
Name2 item1 item2 item3 item4 item5
Could someone please suggest how I can get this list back into the html table?