basically I have PHP and jquery code in my <td>
that will allow inline editing
<td>
<div contenteditable="true" onBlur="updateValue(this, 'lName', '<?php echo $id;?>')" onClick="activate(this)"><?php echo $lName; ?></div>
</td>
and I want to re-apply that same effect on another, ajax and JSON-based table whenever they get appended.
success: function(data) {
data.forEach(function(dt) {
$("#tbody2").append(
"<tr>"
" <td><div contenteditable="true" onBlur="updateValue(this, 'lName', dt.personId ") onClick="activate(this)">" dt.lName "</div></td>"
"</tr>");
});
dt.personId
and dt.lName
do exist.
It keeps saying
uncaught syntax error, missing ) after argument list
I would assume it would be an escaping problem for the function parameters but I can't recognize where.
CodePudding user response:
The problem is this " <td><div contenteditable="true" onBlur="updateValue(this, 'lName', dt.personId ")
If you look at the line, jquery will think that you line starts and end at " <td><div contenteditable="
because this is the first and next "
So you have to either swap some of the "
with '
or escape them by \n
$("#tbody2").append(
"<tr>"
" <td><div contenteditable='true' onBlur='updateValue(this, \'lName\'," dt.personId ")' onClick='activate(this)'>" dt.lName "</div></td>"
"</tr>"); });
CodePudding user response:
You've mismatched of using brackets.
data.forEach(function(dt){
$("#tbody2").append(
"<tr><td><div contenteditable='true' onBlur='updateValue(this, " dt.lName ", dt.personId )' onClick='activate(this)" dt.lName "</div></td></tr>"
);
});
CodePudding user response:
The code you have written has two "{" and only one "}".
Have you tried completing the brackets?