Hi,
I'm trying to do the following:
1. Click on a row (ANY cell of that row)
2. Depending on where I clicked, a javascript function should get the value of EACH cell in THAT row, and populate it to text boxes.
Below is my code thus far:
<html>
<head>
<title>
Trial & Error - Table Cells
</title>
</head>
<body>
<script type="text/javascript">
function getRow(t) {
var col=t.cellIndex;
var row=t.parentNode.rowIndex;
var tableRow = document.getElementById("selectRow");
var tableCells = tableRow.getElementsByTagName("td");
document.testForm.inputA.value = (tableCells[0].innerText);
document.testForm.inputB.value = (tableCells[1].innerText);
document.testForm.inputC.value = (tableCells[2].innerText);
document.testForm.inputD.value = (tableCells[3].innerText);
document.testForm.inputE.value = (tableCells[4].innerText);
document.testForm.inputF.value = (tableCells[5].innerText);
document.testForm.inputG.value = (tableCells[6].innerText);
}
</script>
<form name="testForm" action='test6.html'>
<table border='1' style="background-color:black; color:white">
<tr id="selectRow">
<td width='150px' onclick="getRow(this)">
<b>Test A</b>
</td>
<td onclick="getRow(this)">
<b>Test B</b>
</td>
<td onclick="getRow(this)">
<b>Test C</b>
</td>
<td onclick="getRow(this)">
<b>Test D</b>
</td>
<td onclick="getRow(this)">
<b>Test E</b>
</td>
<td onclick="getRow(this)">
<b>Test F</b>
</td>
<td onclick="getRow(this)">
<b>Test G</b>
</td>
</tr>
<tr>
<td width='150px' onclick="getRow(this)">
<b>Test 1</b>
</td>
<td onclick="getRow(this)">
<b>Test 2</b>
</td>
<td onclick="getRow(this)">
<b>Test 3</b>
</td>
<td onclick="getRow(this)">
<b>Test 4</b>
</td>
<td onclick="getRow(this)">
<b>Test 5</b>
</td>
<td onclick="getRow(this)">
<b>Test 6</b>
</td>
<td onclick="getRow(this)">
<b>Test 7</b>
</td>
</tr>
<tr>
<td>
<input type='text' name='inputA' value=''/>
</td>
<td>
<input type='text' name='inputB' value=''/>
</td>
<td>
<input type='text' name='inputC' value='' />
</td>
<td>
<input type='text' name='inputD' value='' />
</td>
<td>
<input type='text' name='inputE' value='' />
</td>
<td>
<input type='text' name='inputF' value='' />
</td>
<td>
<input type='text' name='inputG' value='' />
</td>
</tr>
</table>
</form>
</body>
</html>
Everything works perfectly EXCEPT that I cannot utilise this with more than one row. Could someone please test this and tell me how I can make it more dynamic?
Say for example I was dynamically generating table rows and it would be unknown to me how many rows there would be until the program ran; how would I be able to make this function detect which information to populate into input areas?
Thanks a lot,
-Ash