Reputation: 23
Well, i have a table generator, with the data of mysql db.
First, the code:
PHP
while($result = mysqli_fetch_assoc($SQL)){
$tbl->addCell("<p onBlur = 'editTable(" . $result['id_user'] . ", this, 'Name')' contentEditable = 'true'>" . $result['Name'] . "</p>");
$tbl->addCell("<p onBlur = 'editTable(" . $result['id_user'] . ", this, 'Username')' contentEditable = 'true'>" . $result['Username'] . "</p>");
$tbl->addCell("<p onBlur = 'editTable(" . $result['id_user'] . ", this, 'Email')' contentEditable = 'true'>" . $result['Email'] . "</p>");
$tbl->addCell("<p onBlur = 'editTable(" . $result['id_user'] . ", this, 'Grade')' contentEditable = 'true'>" . $result['Grade'] . "</p>" );
$tbl->addCell("<input type = 'button' class = 'Edit-TBB' value = 'Edit'>
<input type = 'button' class = 'Delete-TBB' value = 'Delete'>");
$tbl->addRow();
}
AJAX
function editTable(id, new_text, column) {
$.ajax({
url: "../PHP/Configuracion/edit_grade.php",
type: "POST",
data: 'id='+id+'&text='+new_text.innerText,
success: function(data){
alert(column);
}
});
}
Here is the problem:
I have this 'editTable(" . $result['id_user'] . ", this, 'Name')'
if i change the code in Chrome like this ... It works, but i don't know what i need to change at the code editor.
What i need to change?
THANKS!
Upvotes: 1
Views: 50
Reputation: 552
You have to use double quotes for your onBlur
value since you are using single quotes to denote a js string as a parameter. To do this, you need to escape a double quote in your php. So change the addCell
calls to look like:
addCell("<p onBlur=\"editTable(" . $result['id_user'] . ", this, 'Name')\" contentEditable = 'true'>");
Upvotes: 1