Get value of a loop generated table cell via onClick
Hello,
I am trying to get the value of a table cell that is generated by a php loop. The purpose is so eventually I can click a row out of a list and have it take me to a form view of the list item that is clicked. I've searched and searched for the last few days for something with no luck. I run across a lot of hits that tell me I need to have an id for everysingle thing I click on but there has to be a better way.
function as best I could make
Code:
function test() {
var elTableRow = document.getElementById("tr");
var elTableCells = elTableRow.getElementsByTagName("gtrpart");
alert(elTableCells[0].innerText);
}
and my loop
PHP Code:
echo "<table class='info' border='2'align='center'width='1050px'>";
$color1 = "#CCCCCC";
$color2 = "#FFFFFF";
$row_count = 0;
echo "<tr class='tablehead'> <th style='display: none;'>GTR Part Number</th> <th>Part Number</th> <th>REV</th> <th>Description</th> <th>Customer</th> <th>Qty</th> <th>Location</th> </tr>";
while($row = mysqli_fetch_array( $result ))
{
$row_color = ($row_count % 2) ? $color1 : $color2;
echo "<tr onClick='test()' class='data' bgcolor='$row_color'><td style='display: none;' align='center'>";
echo $row['gtr_part_number'];
echo "</td><td align='center'>";
echo $row['part_number'];
echo "</td><td align='center'>";
echo $row['rev'];
echo "</td><td align='center'>";
echo $row['description'];
echo "</td><td align='center'>";
echo $row['customer'];
echo "</td><td align='center'>";
echo $row['qty'];
echo "</td><td align='center'>";
echo $row['location'];
echo "</td></tr>";
$row_count++;
As you can see in my function I right now only want an alert box to pop up telling me the value of the cell I clicked on. Is there a way to do this?
Any help would be greatly appreciated
Thanks,
Austin