Web Analytics Made Easy -
StatCounter JavaScript string variables - CodingForum


No announcement yet.

JavaScript string variables

  • Filter
  • Time
  • Show
Clear All
new posts

  • JavaScript string variables

    I have noticed that when I place a string with quotes within another quote, browser gets confused, For example:

    var test='This is a test for another "<b>Test</b>" from another "<a>world</a> and another time';

    When I use the test variable in the JS, string doesn't appear in the browser. If I use a simple variable w/ no quotes or tags inside, string appears fine.

    I'm using IE 6.0.26

  • #2
    If the string starts with a double quote (") you can use single quotes inside the string,and you have to escape the double quotes.

    var test="This is a test for another \"<b>Test</b>\" from another \"<a>world</a> and another time";


    • #3
      Can't I use double quotes within double quotes with escape character?


      • #4
        I would suggest that if you use special characters, instead of using the character itself, it would be better to use the codes for them. For eg the double quote(") has a code &quot;

        Codes for other characters are also available.
        Scripting | JavaScripts | PerlScripts | Python Scripts | Articles | My Journal


        • #5
          Can you please explain in an example what you mean by code?


          • #6
            The code of a character is an ampersand (&) followed by its code, followed by a semicolon ( ; ). For instance to get the copyright symbol, you enter:

            & + copy + ;
            You'd write that all together without the plus signs, its just that this forum accepts the code and changes them so you can't see the code.

            Which results in &copy;.

            The code for the quotes he's referring to is ampersand, followed by the word "quot" and the semicolon. Just insert that and it will produce a quote that is automatically escaped in HTML. See:

            &quot;I used the code for quotes!&quot;
            New to the CF scene
            Last edited by ObiwanJebroni; Jul 8, 2002, 06:01 PM.
            -Obiwan Jabroni
            May the Schwartz be With You


            • #7
              Where can I get the listing of these codes? Is there a webpage?


              • #8


                Their actual name is "character entities".

                I don't get this thread: your original question was a perfectly good one and, yes, you can escape (literal) quotes within other (delimeter) quotes easily, Bosko's original answer.