newline character in string constant

Discussion in 'Javascript' started by shobhit.mathur@gmail.com, Jul 16, 2005.

  1. Guest

    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
    , Jul 16, 2005
    #1
    1. Advertising

  2. writes:

    > 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
    --
    Lasse Reichstein Nielsen -
    DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
    'Faith without judgement merely degrades the spirit divine.'
    Lasse Reichstein Nielsen, Jul 16, 2005
    #2
    1. Advertising

  3. wrote:
    > 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.
    Christopher J. Hahn, Jul 16, 2005
    #3
  4. Guest

    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
    , Jul 18, 2005
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. mimmo
    Replies:
    4
    Views:
    27,956
  2. Daniel Mark
    Replies:
    6
    Views:
    70,757
    Tim Chase
    Sep 28, 2006
  3. Brand Bogard

    8 bit character string to 16 bit character string

    Brand Bogard, May 25, 2006, in forum: C Programming
    Replies:
    8
    Views:
    735
    those who know me have no need of my name
    May 28, 2006
  4. sinbad
    Replies:
    7
    Views:
    656
    sinbad
    Jun 19, 2008
  5. emeraldsky23

    warning: multi-character character constant error

    emeraldsky23, Jan 15, 2011, in forum: C Programming
    Replies:
    0
    Views:
    1,020
    emeraldsky23
    Jan 15, 2011
Loading...

Share This Page