| Author |
Setting JSP with newline character to Javascript
|
venkat warlu
Greenhorn
Joined: Mar 05, 2008
Posts: 7
|
|
Hi all, Thanks in advance. I am trying to set a text area string with newline characters in it to a java script variable using jsp like below:
document.form.textarea.value = '<%=jspStringVariable%>';
But it is throwing error like "Unterminated String Constant" error. How to set the jsp value to my java script.
Actually i am trying to retain my value in textarea while i self submit the form to reload some other option values.
Regards
Venkat
|
 |
Paul Clapham
Bartender
Joined: Oct 14, 2005
Posts: 16483
|
|
|
You should modify that string by replacing each of the newline characters by the string "\n", which is the Javascript escape for the newline.
|
 |
venkat warlu
Greenhorn
Joined: Mar 05, 2008
Posts: 7
|
|
Paul, I am trying to do something like this:
<% String str ="";
for(int i=0; i < TempStr.length(); i++){
if(Character.getNumericValue(TempStr.charAt(i))<0){
str = str + "\n";
}else{
str = str + TempStr.charAt(i);
}
}
%>
And then in JS:
<script>
function fn(){
document.form.textarea.value = '<%=str%>';
}
</script>
It is still not working.
Regards
Venkat
|
 |
Bear Bibeault
Author and ninkuma
Marshal
Joined: Jan 10, 2002
Posts: 56183
|
|
Have you looked at the HTML and script that's being sent to the client? Is it correct? if not, what can you do to correct it?
Just saying "it doesn't work" isn't helping anyone help you.
|
[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About Bear]
|
 |
venkat warlu
Greenhorn
Joined: Mar 05, 2008
Posts: 7
|
|
|
Thanks Bear for the code tag link. I worked it out myself. I replaced character by character as suggested by Paul. Thanks for your help.
|
 |
 |
|
|
subject: Setting JSP with newline character to Javascript
|
|
|