I want to make my table editable only for columns with Home_Score and Away_Score names
//edit.js file
$(function() {
//when a td element within tbody is clicked
$('tbody').on('click','td',function() {
//call displayform, passing td jQuery element
displayForm( $(this) );
});
});
//table.php file
<?php
$sql = "SELECT * FROM predict WHERE Fixture_ID BETWEEN '1' and '10' ";
$results = $dbh->query($sql);
$rows = $results->fetchAll();
foreach ($rows as $row) {
echo '<tr id="'.$row['Fixture_ID'].'">';
echo '<td class="Home_Team">'.$row['Home_Team'].'</td><td class="Home_Score">'.$row['Home_Score'].'</td>';
echo '<td class="Away_Score">'.$row['Away_Score'].'</td><td class="Away_Team">'.$row['Away_Team'].'</td>';
echo '</tr>';
}
?>
I believe you could do this
$(function() {
//when a td element within tbody is clicked
$('tbody').on('click', 'td.Home_Score, td.Away_Score', function() {
//call displayform, passing td jQuery element
displayForm( $(this) );
});
});
Alternatively, as suggested in another answer, add another class to the cells you want to be able to edit, and use that as the selector.
assuming you be adding rows you can add a class to just the rows you put the vales
<?php
$sql = "SELECT * FROM predict WHERE Fixture_ID BETWEEN '1' and '10' ";
$results = $dbh->query($sql);
$rows = $results->fetchAll();
foreach ($rows as $row) {
echo '<tr id="'.$row['Fixture_ID'].'">';
echo '<td class="Home_Team">'.$row['Home_Team'].'</td><td class="Home_Score editable">'.$row['Home_Score'].'</td>';
echo '<td class="Away_Score editable">'.$row['Away_Score'].'</td><td class="Away_Team">'.$row['Away_Team'].'</td>';
echo '</tr>';
}
?>
then you can update your selector
$('tbody').on('click','.editable',function() {