Please help!
I'm trying to get the individual value of a row's value from my table. I'm using Javascript to show the value when the function is called from clicking the button beside the value in the table.
This is what the table look likes:
Name_1 737 <button>Run JS</button>
Name_2 729 <button>Run JS</button>
Name_3 730 <button>Run JS</button>
This is the file:
<table>
<?
$sql = mysql_query("SELECT * FROM clients WHERE id = '1'");
while($row = mysql_fetch_array($sql)){
$name = $row['client_name'];
$c_id = $row['client_id'];
$id_array[] = $c_id;
echo '<table id="myTable">
<tr>
<td>'.$name.'</td>
<td class="client_id">'.$c_id.'</td>
<td><button onclick="js_function()">Run JS</button></td>
</tr>
</table>';
}
?>
</table>
<script>
var c_id = document.getElementsByClassName("client_id");
function js_function() {
for(var i = 0; i < c_id.length; ++i){
var client_id = c_id[i].innerHTML;
}
document.write(client_id);
}
</script>
When I click any of the buttons showing in the table I always end of up with the value: 730 which is the same value as c_id[2].innerHTML;