I have tried for following code in javascript, but I get:
identifier starts immediately after numeric literal
error is ing for following script, example mcnDel="016160A1"
<script>
mcnDel="016160A1"
var val="<a href='javascript: void(0);' onclick='removeRow("+mcnDel+");'><img src=images/delete.png></a></a></td>"
</script>
I have tried for following code in javascript, but I get:
identifier starts immediately after numeric literal
error is ing for following script, example mcnDel="016160A1"
<script>
mcnDel="016160A1"
var val="<a href='javascript: void(0);' onclick='removeRow("+mcnDel+");'><img src=images/delete.png></a></a></td>"
</script>
Share
Improve this question
edited Jul 6, 2017 at 9:36
vsync
130k59 gold badges340 silver badges421 bronze badges
asked Aug 26, 2014 at 15:11
chayachaya
4234 gold badges11 silver badges21 bronze badges
2
- 1 Are you inserting partial HTML elements, and do you really have an anchor inside an anchor ? – adeneo Commented Aug 26, 2014 at 15:13
-
2
It is confusing why you have a
</a>
and</td>
at the end of your string. – epascarello Commented Aug 26, 2014 at 15:21
5 Answers
Reset to default 10You need to wrap the string with quotes.
onclick='removeRow("+mcnDel+");'
needs to be
onclick='removeRow(\""+mcnDel+"\");'
FYI, I got that error while trying to use BigInt()
and big integer litterals (e.g. 123n
on Safari for iOS.
Dont forget Javascript id cannot start with a number, make sure the value of your variable is not starting with a number.
I hope this answer maybe help another : when we want to concat or add something with a string in Js we must use single quotation. for example we have :
alert(@ViewBag.IsSecondStepAccepted) === error :identifier starts immediately after numeric literal
but if I use
alert('@ViewBag.IsSecondStepAccepted')
everything is OK.
In my case problem was in numeric literal with an underscore
1_000
after removing the underscore my code started to work