Solved

Unterminated string Error?

Posted on 2002-07-12
8
454 Views
Last Modified: 2012-05-05
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
Comment
Question by:nesifa
8 Comments
 
LVL 4

Expert Comment

by:mberumen
ID: 7149658
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
 

Author Comment

by:nesifa
ID: 7149859
vbcrlf equals to what chr(100 or chr(13). I did do vbcrlf but that did not work.
Thanks.
0
 
LVL 4

Accepted Solution

by:
mberumen earned 50 total points
ID: 7149913
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
 
LVL 8

Expert Comment

by:drittich
ID: 7149925
How you handle the line feed depends upon what you are doing with jsstrfromdb.  Can you explain that part?
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 11

Expert Comment

by:mouatts
ID: 7150516
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
 

Expert Comment

by:dotjock
ID: 7151999
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
 
LVL 29

Expert Comment

by:Göran Andersson
ID: 7153256
Nope, mberumen.
vbCrLf = chr(13)+chr(10)
0
 
LVL 4

Expert Comment

by:mberumen
ID: 7154596
Thanks for setting the record straight GreenGhost.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you ever needed to get an ASP script to wait for a while? I have, just to let something else happen. Or in my case, to allow other stuff to happen while I was murdering my MySQL database with an update. The Original Issue This was written…
I was asked about the differences between classic ASP and ASP.NET, so let me put them down here, for reference: Let's make the introductions... Classic ASP was launched by Microsoft in 1998 and dynamically generate web pages upon user interact…
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

895 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now