Reputation: 6110
I have created my table dynamically and in one of my td's I have function where I'm passing two different parameters. One of them is ID and does not need quotes around but second parameter need single quotes and I tried so many combinations like "e; or \' and I could not get what I need. Here is my code:
tbl +="<td><a onClick='DeleteRes(slotsPtc,"+jsData[key].res_ID+")'></a></td>
Code above gave me this:
<a onclick="DeleteRes(slotsPtc,327)"></a>
I'm missing single quotes around first parameter slotsPtc
if anyone can help how I can put single quotes around that parameter please let me know. Thanks.
Upvotes: 0
Views: 262
Reputation: 21575
You can use '
(or '
) as a single quote in HTML:
tbl += "<td><a onClick='DeleteRes('slotsPtc',"+jsData[key].res_ID+")'></a></td>";
Upvotes: 1
Reputation: 141907
You can insert quotes in a string by escaping them with a \
character. I recommend using escaped double quotes for your onclick attribute value and then you can use single quotes without escaping:
tbl +="<td><a onClick=\"DeleteRes('slotsPtc',"+jsData[key].res_ID+")\"></a></td>
Upvotes: 1