I've got an html table populated by a php foreach routine. One field in this table is an Input type=checkbox. The goal is to run a javascript function when the user checks the checkbox. But, since the checkbox is in a table populated by a foreach routine, I'm having some problems. Below is the applicable code for my table:
Code: Select all
<?php
foreach($results as $row)
{
$bk_owner = $row['BookOwner'];
$addrss_owner = $row['AddressOwner'];
$f_name = $row['FName'];
$l_name = $row['LName'];
$email = $row['EmailAddress'];
$d_phone = $row['DeskPhone'];
$ext = $row['Ext'];
$cell = $row['CellPhone'];
$title = $row['Title'];
echo "<tr>";
echo "<td class='a'>".$l_name ."</td>";
echo "<td class ='a'>".$f_name ."</td>";
echo "<td class ='c'>".$email ."</td>";
echo "<td class ='a'>".$d_phone ."</td>";
echo "<td class='b'>".$ext."</td>";
echo "<td class='a'>".$cell."</td>";
echo "<td class='c'>".$title."</td>";
echo "<td class='b'><input type='checkbox' id='chk_Bx' value=". $addrss_owner. " onClick='selectFunction()'></input></td>";
echo "</tr>";
}
echo"</tbody>";
?>Code: Select all
echo "<td class='b'><input type='checkbox' id='chk_Bx' value=". $addrss_owner. " onClick='selectFunction()'></input></td>";Following is the javascript code for selectFunction():
Code: Select all
function selectFunction(){
var check = document.getElementById("chk_Bx").checked;
var val = document.getElementById("chk_Bx").value;
alert(val);
}Also, if I alert out check, it continually returns false, even if I've checked the box and it should read true. I am assuming this is also related to the foreach table presentation.
How do I grab ONLY the primary key value, or checked true/false for the applicable record?
Thanks in advance:
Pavilion