I have a table where I am creating one button in each row dynamically. So if we have 3 rows, we will have 3 buttons at the 3rd column of each row.
I am facing a problem at two levels :
i) Assigning a single function that will be called at 'onClick' of all the buttons. ii) Reading the values of the corresponding columns of the button which has been pressed, for example : Say we have 3 columns, and I press the button at the 2nd row , 3rd column, I need to read the values of the 2nd row, 1st and 2nd column.
The entire thing is built up dynamically.
Here is the table:
<body>
<div id="up"></div>
<table id = "tab" style="width:500px">
<tr>
<th>Date/Time</th>
<th>Session Activity</th>
<th>Action</th>
</tr>
<?php
$uid = $_SESSION["uid"];
$client = $_SESSION["Client"];
$con = mysqli_connect('localhost', 'root', '12345', 'MyDB');
if (mysqli_connect_errno()){
echo "<option value='".'0'."'>".'Connection Error'."</option>";
exit();
}else{
$res=mysqli_query($con, "select * from TL_Session_Notes Where Uid = '".$uid."' AND CName = '".$client."'");
while($row=mysqli_fetch_array($res))
{
echo "<tr><td>".$row['Sn_date'].'/'.$row['Sn_time']."</td><td>".$row['Sn_activity']."</td>".
"<td id = '"."openBtns"."'><input type='"."button"."' class = '"."btns"."' value = '"."Open Session Note"."' action = '"."OpenSession()"."'/>"."</td></tr>";
}
}
mysqli_close($con);
?>
</table>
<div id="down"></div>
</body>
Here is the code I've tried to get the (i) part working :
<script>
$(document).ready(function(){
$("openBtns").on('click', '.btns', function() {
OpenSession();
});
});
function OpenSession(){
window.location.replace('Sessions.php');
}
</script>
Need some help on how to do this and where is my approach going wrong.