Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 8 of 8
  1. #1
    New to the CF scene
    Join Date
    Jun 2002
    Location
    Silicon Valley
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 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
    Regular Coder
    Join Date
    Jun 2002
    Location
    The Netherlands
    Posts
    217
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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
    New to the CF scene
    Join Date
    Jun 2002
    Location
    Silicon Valley
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Can't I use double quotes within double quotes with escape character?

  • #4
    Regular Coder
    Join Date
    Jun 2002
    Location
    Mumbai, India
    Posts
    218
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.

  • #5
    New to the CF scene
    Join Date
    Jun 2002
    Location
    Silicon Valley
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Can you please explain in an example what you mean by code?

  • #6
    New Coder
    Join Date
    Jun 2002
    Posts
    70
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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:

    Code:
    & + 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;
    Last edited by ObiwanJebroni; 07-08-2002 at 10:01 PM.
    -Obiwan Jabroni
    May the Schwartz be With You

  • #7
    New to the CF scene
    Join Date
    Jun 2002
    Location
    Silicon Valley
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Where can I get the listing of these codes? Is there a webpage?

  • #8
    Senior Coder
    Join Date
    Jun 2002
    Posts
    1,404
    Thanks
    2
    Thanked 32 Times in 32 Posts
    Resource:

    http://www.bbsinc.com/symbol.html

    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.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •