最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

SyntaxError: identifier starts immediately after numeric literal. Passing php variable to JavaScript - Stack Overflow

programmeradmin1浏览0评论

I am trying to pass in two variables to a JavaScript function: the input itself and the user id. I call the function using the onclick attribute of the input.

 echo "<input type = 'submit' class = 'replyButton' id = 'replyButton'
 value = 'reply' onclick = 'insertComment(this, $user_id);'>";

The variables go into a JavaScript function:

function insertComment(input, user)
{
     //use input and user id to carry out tasks.
} 

The error message given is at the function call to 'insertComment()' in the onclick of the input. The error message looks like this:

SyntaxError: identifier starts immediately after numeric literal    

       insertComment(this, 9f60d869342a);

I have tried multiple quote and dot binations and have checked the other posts on StackOverFlow. They were all to no avail. Your help in resolving this error is greatly appreciated.

I am trying to pass in two variables to a JavaScript function: the input itself and the user id. I call the function using the onclick attribute of the input.

 echo "<input type = 'submit' class = 'replyButton' id = 'replyButton'
 value = 'reply' onclick = 'insertComment(this, $user_id);'>";

The variables go into a JavaScript function:

function insertComment(input, user)
{
     //use input and user id to carry out tasks.
} 

The error message given is at the function call to 'insertComment()' in the onclick of the input. The error message looks like this:

SyntaxError: identifier starts immediately after numeric literal    

       insertComment(this, 9f60d869342a);

I have tried multiple quote and dot binations and have checked the other posts on StackOverFlow. They were all to no avail. Your help in resolving this error is greatly appreciated.

Share Improve this question asked Jun 30, 2013 at 16:46 jlagomarsinijlagomarsini 211 gold badge1 silver badge2 bronze badges 1
  • Possible duplicate of SyntaxError: identifier starts immediately after numeric literal in Firebug – Amir Commented Nov 23, 2015 at 5:57
Add a ment  | 

1 Answer 1

Reset to default 5

you need to quote the user id

echo "<input type = 'submit' class = 'replyButton' id = 'replyButton'
 value = 'reply' onclick = 'insertComment(this, \"$user_id\");'>";
发布评论

评论列表(0)

  1. 暂无评论