I’m calling a JavaScript function from an onclick event in a JSP page.
<%
String value = "06654"
%>
<body>
<a href="javascript://" onclick="myFunction(<%= value %>)">Click Me!</a>
</body>
My JavaScript function is like this
function myFunction(myString)
{
alert(myString);
//Do Stuff;
}
myString is equal to 06654 but I’m getting 6654 when I alerts it’s value. How do I stop js from automatically parsing the String to an int?
If you output the string into the page, the result will be
which is obviosly interpreted as a number. To make it a JavaScript string, put quotes around it: