newline character in string constant

S

shobhit.mathur

Hi!

I have a form with a textarea field. I want to validate the input from
the textarea using javascript. Suppose I want to check that the user
has not entered the string:
"Hello
World!"

To do this I am using the script:
form["text"].value == "Hello\nWorld"

But this gives an "unterminated string constant error" because the
browser converts this to:
form["text"].value == "Hello
World"

So how do I do my check?

Regards,
Shobhit
 
L

Lasse Reichstein Nielsen

To do this I am using the script:
form["text"].value == "Hello\nWorld"

But this gives an "unterminated string constant error" because the
browser converts this to:
form["text"].value == "Hello
World"

No it doesn't, unless you are doing something more that you haven't
shown us. So, give a link to the page where it fails (preferably
a small, self-contained page showing only the problem).

/L
 
C

Christopher J. Hahn

Hi!

I have a form with a textarea field. I want to validate the input from
the textarea using javascript. Suppose I want to check that the user
has not entered the string:
"Hello
World!"

To do this I am using the script:
form["text"].value == "Hello\nWorld"

But this gives an "unterminated string constant error" because the
browser converts this to:
form["text"].value == "Hello
World"

So how do I do my check?

Regards,
Shobhit

This doesn't happen in pure JavaScript.

I'm going to take a wild guess that this line of code is being output
by PHP, PERL, or some similar server-side tongue. In this case, it is
the server-side language that is interpolating the \n.

If this is the case, depending on the language and the way you're
outputing it, you may be able to double-escape it to \\n.
 
S

shobhit.mathur

I am using perl to output the script. Now I am double-escaping it using
\\n. Though the script is output correctly i.e form["text"].value ==
"Hello\nWorld" but when the check still fails.

Shobhit
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top