Reputation: 123
Why i get Uncaught SyntaxError: Unexpected token }:
btn = '<td class="sentBut"><button type="button" class="btn btn-info" onClick="sentMail("'+tr[0]+'","'+tr[1]+'","'+tr[2]+'")">הזמן/י</button></td>';
What wrong here:
"'+tr[0]+'","'+tr[1]+'","'+tr[2]+'"
When remove this,it will work.
Thanks.
Upvotes: 1
Views: 93
Reputation: 2944
You can use following method. This will reduce your formatting issue.
var DataReplacement = function ()
{
var s = arguments[0];
for (var i = 0; i < arguments.length - 1; i++)
{
var reg = new RegExp("\\{" + i + "\\}", "gm");
s = s.replace(reg, arguments[i + 1]);
}
return s;
}
Use the function like below
var func = DataReplacement("sendEmail('{0}', '{1}', '{2}')", tr[0], tr[1], tr[2]);
btn = '<td class="sentBut"> \
<button type="button" class="btn btn-info" \
onClick="' + func + '"> yourText \
</button> \
</td>';
Upvotes: 0
Reputation: 4340
The problem is you are using single and double quotes inside of an html tag. html has assigned specific meanings to these. For example, it is probably reading the onClick element like this:
onClick="sentMail("
because your double quote closes the opening quote. Fix it like this:
btn = '<td class="sentBut"><button type="button" class="btn btn-info" onClick="sentMail("'+tr[0]+'","'+tr[1]+'","'+tr[2]+'")">הזמן/י</button></td>';
I know that seems a little crazy but those are html entities.
'
represents '
"
represents "
You can find all of the entities here.
Upvotes: 3