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
1 Answer
Reset to default 5you need to quote the user id
echo "<input type = 'submit' class = 'replyButton' id = 'replyButton'
value = 'reply' onclick = 'insertComment(this, \"$user_id\");'>";