Skip to content Skip to sidebar Skip to footer

Need To Ignore If There Is Any Single Quote Char In Value Come From Expression Language Without Breaking Javascript Code

I am getting a value from the server and directly assigning it to a field using javascript. Below is the code. document.getElementById('myid')='<%= myServerValue%>'; But the

Solution 1:

try HttpUtility.JavaScriptStringEncode

Solution 2:

You need to encode your characters at the server and somehow decode it in the javascript code. There are a few possibilities to achieve that, you can use UTF8 like in this demo The escape and unescape javascript methods are obsolete but you can try String.fromCharCode.

Solution 3:

This no the most clean solution, but it will work just as it is.

document.getElementById('myid')="<%= myServerValue%>";

Post a Comment for "Need To Ignore If There Is Any Single Quote Char In Value Come From Expression Language Without Breaking Javascript Code"