I want to display special chars as an alert box using javascript and jsp…
String encodeString = "ss\ncc";
String test = "DisplayNext('"+encodeString+"')";
String NextLink = "<br><a href='#' onclick="+test+"> Next</a>";
That is
function DisplayNext(Next){
alert(Next);
}
Though I’ve used special chars I am not able to display them in an alert box. How can I sort this out?
Your code produce something like this:
And what you need is:
If you want a line break in javascript it must look as
\\nin java. So use:Also consider using a special function to escape your String objects as javascript values. Google will easily help you find it 😉