473,387 Members | 1,493 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Need avise on javascript and string problem.

Hi,

I am trying to do this bit using client side script in an asp page

var x = "<%ServerVar%>";

The issue is if SerVar has carraige returns the Unterminates String
Constant error is thrown on the client side. With regard to this I can
only manupilate the client side Javascript.

Any thoughts on how i can get the contents of ServerVar on to a
javascript variable?

Thanks,
Tariq

Jul 23 '05 #1
7 1896
On 30 Nov 2004 03:50:01 -0800, Tariq <ta*******@gmail.com> wrote:

[snip]
var x = "<%ServerVar%>";

The issue is if SerVar has carraige returns the Unterminates String
Constant error is thrown on the client side. With regard to this I can
only manupilate the client side Javascript.
Then you're out of luck. Line terminators *must* be escaped, either using
character escapes like \n and \r, or numeric escapes (hex: \x0A or
Unicode: \u000A).
Any thoughts on how i can get the contents of ServerVar on to a
javascript variable?


You will have to escape the value first so that it outputs

var x = 'This string contains\na new line';

instead of

var x = 'This string contains
a new line';

Mike

--
Michael Winter
Replace ".invalid" with ".uk" to reply by e-mail.
Jul 23 '05 #2
If this is ASP, try and do a replace on the string you are going to put into
the JS before the JS section is written the call is something like:

strJSString = replace(strString, "vbcrlf", "/n")

Then response.write strJSString to the screen, equally you could chnage all
carriage returns to just be spaces in a similar way.

Hope that helps
Stu
Jul 23 '05 #3
"Michael Winter" <M.******@blueyonder.co.invalid> wrote in message news:<opsh9134uox13kvk@atlantis>...
On 30 Nov 2004 03:50:01 -0800, Tariq <ta*******@gmail.com> wrote:

[snip]
var x = "<%ServerVar%>";

The issue is if SerVar has carraige returns the Unterminates String
Constant error is thrown on the client side. With regard to this I can
only manupilate the client side Javascript.


Then you're out of luck. Line terminators *must* be escaped, either using
character escapes like \n and \r, or numeric escapes (hex: \x0A or
Unicode: \u000A).
Any thoughts on how i can get the contents of ServerVar on to a
javascript variable?


You will have to escape the value first so that it outputs

var x = 'This string contains\na new line';

instead of

var x = 'This string contains
a new line';

Mike


Wouldn't this do as well? ;)

var x = 'This string contains\
a new line';

(the Macromedia approach, escape the linefeed, avoid the semicolon)
Jul 23 '05 #4
On 30 Nov 2004 10:45:41 -0800, RobB <fe******@hotmail.com> wrote:

[snip]
Wouldn't this do as well? ;)

var x = 'This string contains\
a new line';


No. It's invalid. Line terminators are not allowed to appear in any part
of a string literal. They *must* be escaped.

Yes, some browsers accept it, but (in my opinion) it should not be used as
you're relying on an unspecified extension to the language. Besides, if
you can change CR to \CR, why can't you replace CR with \n?

[snip]

Mike

--
Michael Winter
Replace ".invalid" with ".uk" to reply by e-mail.
Jul 23 '05 #5
On Tue, 30 Nov 2004 19:17:58 GMT, Michael Winter
<M.******@blueyonder.co.invalid> wrote:

[snip]
Besides, if you can change CR to \CR, why can't you replace CR with \n?


Oops. Replace CR with LF.

Mike

--
Michael Winter
Replace ".invalid" with ".uk" to reply by e-mail.
Jul 23 '05 #6
JRS: In article <opsialbslzx13kvk@atlantis>, dated Tue, 30 Nov 2004
19:17:58, seen in news:comp.lang.javascript, Michael Winter <M.Winter@bl
ueyonder.co.invalid> posted :
On 30 Nov 2004 10:45:41 -0800, RobB <fe******@hotmail.com> wrote:

[snip]
Wouldn't this do as well? ;)

var x = 'This string contains\
a new line';


No. It's invalid. Line terminators are not allowed to appear in any part
of a string literal. They *must* be escaped.

Yes, some browsers accept it, but (in my opinion) it should not be used as
you're relying on an unspecified extension to the language. Besides, if
you can change CR to \CR, why can't you replace CR with \n?


Moreover, on RobB's example, the newline is escaped out of existence,
not to a string-compatible version of itself. The string, in systems
(mot necessarily only browsers) that accept that backslash, is

This string containsa new line

so that it is a badly-composed falsehood!

BTW, AIUI, in javascript \n means newline; in different systems, that
might be CR = 13, LF = 10, CRLF, Unicode, ...

--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk DOS 3.3, 6.20; Win98. ©
Web <URL:http://www.merlyn.demon.co.uk/> - FAQqish topics, acronyms & links.
PAS EXE TXT ZIP via <URL:http://www.merlyn.demon.co.uk/programs/00index.htm>
My DOS <URL:http://www.merlyn.demon.co.uk/batfiles.htm> - also batprogs.htm.
Jul 23 '05 #7
Dr John Stockton <sp**@merlyn.demon.co.uk> wrote in message news:<Gi**************@merlyn.demon.co.uk>...
JRS: In article <opsialbslzx13kvk@atlantis>, dated Tue, 30 Nov 2004
19:17:58, seen in news:comp.lang.javascript, Michael Winter <M.Winter@bl
ueyonder.co.invalid> posted :
On 30 Nov 2004 10:45:41 -0800, RobB <fe******@hotmail.com> wrote:

[snip]
Wouldn't this do as well? ;)

var x = 'This string contains\
a new line';


No. It's invalid. Line terminators are not allowed to appear in any part
of a string literal. They *must* be escaped.

Yes, some browsers accept it, but (in my opinion) it should not be used as
you're relying on an unspecified extension to the language. Besides, if
you can change CR to \CR, why can't you replace CR with \n?


Moreover, on RobB's example, the newline is escaped out of existence,
not to a string-compatible version of itself. The string, in systems
(mot necessarily only browsers) that accept that backslash, is

This string containsa new line

so that it is a badly-composed falsehood!


You callin' me a liar? :-o
Jul 23 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Andy Fish | last post by:
Hi, I want to use an anchor tag to invoke some javascript and I've read that it's bad form to use <a href="javascript:foo()"> I've read endless usenet posts and hint sites on the net, they all...
11
by: Jack | last post by:
I have a asp form where among others there are few text boxes and one check box. The checkbox is to indicate whether the entry is final. The checkbox is attahced to a field in table of type...
7
by: Jack Addington | last post by:
I've got a fairly simple application implementation that over time is going to get a lot bigger. I'm really trying to implement it in a way that will facilitate the growth. I am first writing a...
12
by: Jeff S | last post by:
In a VB.NET code behind module, I build a string for a link that points to a JavaScript function. The two lines of code below show what is relevant. PopupLink = "javascript:PopUpWindow(" &...
4
by: Dave | last post by:
I am beginning to write some C# pages to an app I created with VB.Net. There is one VB routine I use frequently - a javascript alert box. I have created a C# version, but it does not handle...
8
by: Pavils Jurjans | last post by:
Hello, I have been developing an Ajax-style framework for couple of years now. Now I am reworking some parts of it. The problem was that I used to use JSON for JavaScript value...
8
by: | last post by:
The problem lies here eval("document.TeeForm.amt.value(S+M)"); S and M suppose to add up and the total suppose to appear on the AMT field but it didn't. Any help? ...
5
by: rocknbil | last post by:
Hello everyone! I'm new here but have been programming for the web in various languages for 15 years or so. I'm certainly no "expert" but can keep myself out of trouble (or in it?) most of the time....
2
by: sorobor | last post by:
dear sir .. i am using cakephp freamwork ..By the way i m begener in php and javascript .. My probs r bellow I made a javascript calender ..there is a close button ..when i press close button...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.