1

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.

2
  • is tr a json array ? Commented May 18, 2016 at 17:42
  • Check the line below this one. You may have an extra } closing bracket. Hard to tell without what line the error is referring to. Commented May 18, 2016 at 17:45

2 Answers 2

3

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(&#34;&#39;+tr[0]+&#39;&#34;,&#34;&#39;+tr[1]+&#39;&#34;,&#34;&#39;+tr[2]+&#39;&#34;)">הזמן/י</button></td>'; 

I know that seems a little crazy but those are html entities.

&#39; represents '

&#34; represents "

You can find all of the entities here.

Sign up to request clarification or add additional context in comments.

2 Comments

I believe the single quotes should be left unencoded as-per the logic of the code.
That looks crazy yea but i will use Mahedi Sabuj its look cleaner and i will adopt the way he use for next time. thanks for help.
0

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>'; 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.