I want to choose only one row at a time from html table... Im using php,html and javascript.. if i choose one row means that the value only show in alert box at a time using javascript.. I wrote some js coding but it shows all the row values one by one in alertbox.. Please anyone help for me..
My html code:
<table BORDER="5">
<tr>
<th colspan="10">
</th>
</tr>
<tr>
<th>Date & Time</th>
<th>Name</th>
<th>Source</th>
<th>Destination</th>
<th>Ride Type</th>
<th>Vehicle Type</th>
<th>Plate No.</th>
<th>Distance</th>
</tr>
<?php $search_data = "";?>
<tbody id="table"style="cursor:pointer"onclick="found(this);">
<tr id="choose">
<?php echo $search_data; ?>
</tr>
</tbody>
</table>
My javascript:
function found(row) {
//alert("hai");
var table=document.getElementById("table");
var cells = table.getElementsByTagName("tr");
for (var i = 0; i < cells.length; i++) {
alert(cells[i].innerHTML);
}
}
My php code: while ($data = mysql_fetch_array($firstattempt)) {
$search_data = "";
$search_data .= "<tr>";
$search_data .= "<td>{$data["DATE"]} & {$data["START_TIME"]}</td>";
$search_data .= "<td>{$data["NAME"]}</td>";
$search_data .= "<td>{$data["START_FROM"]}</td>";
$search_data .= "<td>{$data["END_TO"]}</td>";
$search_data .= "<td>{$data["RIDER_FLAG"]}</td>";
$search_data .= "<td>{$data["VEHICLE_TYPE"]}</td>";
$search_data .= "<td>{$data["PLATE_NO"]}</td>";
$search_data .= "<td>{$distance} Km</td>";
$search_data .= "</tr>";
echo $search_data;
}
My output :