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 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Nov 2007
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Java script Var + double quotes

    Hi,

    How to add double quotes in java script var. I got error if I give double quotes within "".but It's accepting if I give single quotes within "".
    snippet:

    for (i=0;i<Ca.length;i++){

    getModel =getModel +"'"+Ca.options[i].text+"'"+",";

    }

    var getST=getModel+")"+""";

    Thanks in Advance!
    Reena.

  • #2
    Regular Coder Actinia's Avatar
    Join Date
    Feb 2007
    Location
    Essex, UK
    Posts
    250
    Thanks
    1
    Thanked 23 Times in 22 Posts
    Just escape the double quote with a backslash:

    Code:
    getModel =getModel +"\""+Ca.options[i].text+"\""+",";
    John Rostron

  • #3
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,079
    Thanks
    203
    Thanked 2,542 Times in 2,520 Posts
    You can have double quotes " within single quotes ' or vice versa.

    for (i=0; i<Ca.length; i++) {
    getModel = getModel + "'" + Ca.options[i].text + "'" + ",";
    }
    var getST= getModel +')' + '"';

    BTW, the time to say "thanks" is afterwards, not beforehand which gives the impression that you take other people's assistance for granted.


  •  

    Posting Permissions

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