I am trying to edit this table row of an inline edit table. I am able to pass data from my js file to my PHP file for the query. The issue I am having is with getting the data from the table row. Every method I have tried to put table data in a JavaScript variable to send through ajax is not working. I have tried echoing the data, json_encode
, using selectors...
I am new to this so maybe I am making a minor mistake. But I am able to Delete passing the id through an href. I need to edit several table cells and pass the df id:
$df_id = $row['df_id'];
echo '<td class="border-left text-center" id="cg_crit">'.$row['ContentGrammarCritical'].'</td>';
echo '<td class="text-center">'.$row['ContentGrammarMajor'].'</td>';
echo '<td class="text-center">'.$row['ContentGrammarMinor'].'</td>';
echo '<td class="border-left text-center" >'.$row['functionalCritical'].'</td>';
echo '<td class="text-center">'.$row['functionalMajor'].'</td>';
echo '<td class="text-center">'.$row['functionalMinor'].'</td>';
echo '<td class="border-left text-center" >'.$row['NonfunctionalCritical'].'</td>';
echo '<td class="text-center">'.$row['NonfunctionalMajor'].'</td>';
echo '<td class="text-center">'.$row['NonfunctionalMinor'].'</td>';
Here is my code.
The Edit Table
while($row=mysqli_fetch_assoc($result)) {
$df_id = $row['df_id'];
$convert_day = $row['df_date'];
$day_date = strftime("%A",strtotime($convert_day));
echo '<tr><td>'.$day_date.'</td>';
echo '<td id="pr_name">'.json_encode($row['pr_name']).'</td>';
echo '<td>'.$row['tcs_type'].'</td>';
echo '<td class="text-center" id="rnd">'.$row['df_round'].'</td>';
echo '<td class="border-left text-center" id="cg_crit">'.$row['ContentGrammarCritical'].'</td>';
echo '<td class="text-center">'.$row['ContentGrammarMajor'].'</td>';
echo '<td class="text-center">'.$row['ContentGrammarMinor'].'</td>';
echo '<td class="border-left text-center" >'.$row['functionalCritical'].'</td>';
echo '<td class="text-center">'.$row['functionalMajor'].'</td>';
echo '<td class="text-center">'.$row['functionalMinor'].'</td>';
echo '<td class="border-left text-center" >'.$row['NonfunctionalCritical'].'</td>';
echo '<td class="text-center">'.$row['NonfunctionalMajor'].'</td>';
echo '<td class="text-center">'.$row['NonfunctionalMinor'].'</td>';
echo '<td class="border-left" contenteditable="false"><div class="ticket-actions col-md-2">
<div class="btn-group dropdown">
<a type="button" class="btn dropdown-toggle btn-sm" data-toggle="dropdown">
Manage
</a>
<div class="dropdown-menu">
<a class="dropdown-item editbtn">
<i class="fa fa-reply fa-fw"></i>Edit</a>
<a class="dropdown-item cancelbtn" href="javascript:history.go(0)">
<i class="fa fa-reply fa-fw"></i>Cancel</a>
<button class="dropdown-item savebtn" id="">
<i class="fa fa-check text-success fa-fw"></i>Save</button>
<div class="dropdown-divider"></div>
<a class="dropdown-item" href="DB/defect/delete_defect.php?id='. $df_id .'">
<i class="fa fa-times text-danger fa-fw"></i>Delete</a>
</div>
</div>
</div></td></tr>';
}
THE AJAX
$('.savebtn').click(function() {
$.each(currentTD, function() {
//alert("second if "+currentTD.html());
$(this).prop('contenteditable', false).removeAttr("style");
//var df_id = $(this).('#pr_name');
var df_id2 =
var df_id3 = "45";
console.log(df_id2);
$.post("DB/defect/edit_defect.php", {
df_id: df_id2,
day_date: df_id3
}, function(data) {
console.log(data);
});
$('.editbtn').show();
$('.savebtn').hide();
$('.cancelbtn').hide();
});
})