• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 463
  • Last Modified:

Unterminated string Error?

Hi ,
I have the following code

<%
dim strFromDB
'let say that this is the value returned from a db, probably feed line or carriage return
'strFromDB="this is line 1
'           this is line 2"

%>
<script>

var jsstrfromdb='<%=strFromDB%>';>
because the value coming from DB is in two lines, it gives me a javascript error.
I am trying to use server.htmlencode, unescape... but does not work.
Any suggestion.

Thanks.
Nesifa
0
nesifa
Asked:
nesifa
1 Solution
 
mberumenCommented:
try the replace function

newText=replace(strFromDB,vbcrlf," ")

assuming that your EOL character is vbcrlf  (carriage return, line feed)

you can also evaluate and replace chr(10) or Chr(13)
0
 
nesifaAuthor Commented:
vbcrlf equals to what chr(100 or chr(13). I did do vbcrlf but that did not work.
Thanks.
0
 
mberumenCommented:
I believe is chr(10)+chr(13)

i.e  replace (text, chr(10)+chr(13),"")

BTW.  this is the VBScript sintaxis, Just noticed that you are using JScript  Not sure what is the corresponding statement in JScript.  You might have to write your own replace statement.  
0
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
drittichCommented:
How you handle the line feed depends upon what you are doing with jsstrfromdb.  Can you explain that part?
0
 
mouattsCommented:
Try the following which will replace Carriage returns, line feeds both singularly and together with the correct javascript character literal.


var jsstrfromdb='<%=replace(replace(replace(strFromDB,vbcrlf,"\n"),vbcr,"\r"),vblf,"\f")%>';>


If you just want to remove the character(s) then use the following

var jsstrfromdb='<%=replace(replace(strFromDB,vblf,""),vbcr,"")%>';>

Steve

0
 
dotjockCommented:
Another suggestion.  use the replace function to replace the carrage return with a <p> tag.. or possibly a <br> tag.

something such as this

sVal = replace(sVal, vbCrLf, "<p>")

I usually find it best to replace all carrage returns with <br> so that you dont miss out on a new line.

0
 
Göran AnderssonCommented:
Nope, mberumen.
vbCrLf = chr(13)+chr(10)
0
 
mberumenCommented:
Thanks for setting the record straight GreenGhost.
0

Featured Post

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now