• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Setting JSP with newline character to Javascript

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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

 
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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

 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
venkat warlu
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic