How to handle this seneraio with String in JavaScript?

this isthe code that can help you what is the actual problem

<html>
<head>
</head>
<body>
<textarea cols="20" rows="7" id="someval">

</textarea>
<br>
<input type="button" onClick="showData();" value="CheckValue"/>
<script type="text/javascript">
function showData(){
var multiLineString ="This is some Text
 this is another text";
 document.getElementById('someval').innerHTML=multiLineString;
  }
 </script>
 </body>
 </html>

I am using JSTL(JSP StandardTag Library)

I ma getting value from my db exactly in this format but as like in this case when you run this script in a single browser check console I am getting similar error in my case to

“unterminated string literal”

I hope now you got some more Information about my problems

I think that you may need to gain advice from people who know something about JSP. That is outside my realm of experience.

Ok one thing How can I detect text from textarea that a new line has been started in textarea fields?

I think that you should always assume that a textarea may have a newline in it - no detection needed. Based on that assumption you should always escape the text when you are embedding it as javascript code.

Ok Just one question if you had to store textarea value in the database to preserve all the newlines user has typed how you will store that data of textarea in database and retrieve back in web page using JavaScript

JavaScript has no access to the database - unless you are also running it on the server (eg, Node)

I am just asking there is a Multiple line textarea in your application suppose you have to preserve all the line breaks that user has typed while typing in textarea fields and

you need to show that back in your front end(overlook what is server side lenguage it can be JSP,PHP,.net)

and one more thing like in case of sitepoint while I am typing I can take a nuber of line break but in actual output it just outputs after a single line How can I do that?

I thought that a good solution has been found for this, with escapeJavaScript

I solved My Problem using
functions lag library

first add this library at the top of your JSPpage
and then there is a replace functions that replace all fields

But Now I have just one question suppose If User has types more than one time enter button
suppose 10 times then the text is displaying at the 10th line so all 9 rows are wasted

So like here on sitepoint also if we type more than one enter space it only takes just one para space in the output box How can I do this?

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.