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

霸气de小男生 提交于 2020-01-02 18:04:13

问题


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 combinations and have checked the other posts on StackOverFlow. They were all to no avail. Your help in resolving this error is greatly appreciated.


回答1:


you need to quote the user id

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


来源:https://stackoverflow.com/questions/17392619/syntaxerror-identifier-starts-immediately-after-numeric-literal-passing-php-va

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!