close

[Solved] Uncaught SyntaxError: Invalid or unexpected token

Hello Guys, How are you all? Hope You all Are Fine. Today I get the following error Uncaught SyntaxError: Invalid or unexpected token in javascript. So Here I am Explain to you all the possible solutions here.

Without wasting your time, Let’s start This Article to Solve This Error.

How Uncaught SyntaxError: Invalid or unexpected token Error Occurs?

Today I get the following error Uncaught SyntaxError: Invalid or unexpected token in javascript.

How To Solve Uncaught SyntaxError: Invalid or unexpected token Error ?

  1. How To Solve Uncaught SyntaxError: Invalid or unexpected token Error ?

    To Solve Uncaught SyntaxError: Invalid or unexpected token Error You should pass @item.email in quotes then it will be treated as string argument
    <td><a href ="#" onclick="Getinfo('@item.email');" >6/16/2016 2:02:29 AM</a> </td>

  2. Uncaught SyntaxError: Invalid or unexpected token

    To Solve Uncaught SyntaxError: Invalid or unexpected token Error You should pass @item.email in quotes then it will be treated as string argument
    <td><a href ="#" onclick="Getinfo('@item.email');" >6/16/2016 2:02:29 AM</a> </td>

Solution 1

You should pass @item.email in quotes then it will be treated as string argument

<td><a href ="#"  onclick="Getinfo('@item.email');" >6/16/2016 2:02:29 AM</a>  </td>

Otherwise, it is treated as variable thus error is generated.

Solution 2

I also had an issue with multiline strings in this scenario. @Iman’s backtick(`) solution worked great in the modern browsers but caused an invalid character error in Internet Explorer. I had to use the following:

'@item.MultiLineString.Replace(Environment.NewLine, "<br />")'

Then I had to put the carriage returns back again in the js function. Had to use RegEx to handle multiple carriage returns.

// This will work for the following:
// "hello\nworld"
// "hello<br>world"
// "hello<br />world"
$("#MyTextArea").val(multiLineString.replace(/\n|<br\s*\/?>/gi, "\r"));

Summery

It’s all About this issue. Hope all solution helped you a lot. Comment below Your thoughts and your queries. Also, Comment below which solution worked for you? Thank You.

Also Read

Leave a Comment