using quotes in variables

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • asd987

    using quotes in variables

    Hi,

    I use document.write in a HTML-document to display same information. Now I
    have a problem displaying text that sometimes contains two kinds of quotes
    simultanelisly. I don't know on beforehand if this is the situation. See
    example:

    ## ---

    <script language="JavaS cript">
    var a1; // text to display - variable between '
    var a2; // text to display - variable between "

    a1='This text (a1) contains the single (') and the double (") quote and is
    placed between single quotes. How can I display this variable using
    document.write? '

    a2="This text (a2) contains the single (') and the double (") quote and is
    placed between double quotes. How can I display this variable using
    document.write? "

    document.write( ""+a1+" "+a2+"");
    </script>

    ## ---

    Is there possibly another character to use for placing around the text? Or
    any other solution?

    Thanks,

    Sjoerd



  • wasntme

    #2
    Re: using quotes in variables

    my poor example, view in notepad or what ever, and hope the code goes
    through the post intact..
    <html><head><ti tle></title>
    </head><body text="#000000">
    <script language="JavaS cript"><!--
    var a1='This text (a1) contains the single'
    +'(\')and the double (") quote and is '
    +'placed between single quotes.'
    +'How can I display this variable using '
    +'document.writ e?<br><br>'
    var a2="This text (a2) contains the "
    +"single (') and the double (\") "
    +"quote and is placed between "
    +"double quotes. How can I display "
    +"this variable using "
    +"document.writ e?<br><br>"
    var b1='document.wr ite(\'"+a1"\"+a 2+"\');<br>'
    var b2="document.wr ite(\"'+a1+''+a 2'\");"
    var z=a1+a2+b1+b2;
    with(document){ write(z);} //--></script>
    </body></html>

    Comment

    • Janwillem Borleffs

      #3
      Re: using quotes in variables

      asd987 wrote:[color=blue]
      > a1='This text (a1) contains the single (') and the double (") quote
      > and is placed between single quotes. How can I display this variable
      > using document.write? '
      >
      > a2="This text (a2) contains the single (') and the double (") quote
      > and is placed between double quotes. How can I display this variable
      > using document.write? "
      >[/color]

      a1='This text (a1) contains the single (\') and the double (") quote';
      a2="This text (a2) contains the single (') and the double (\") quote";
      [color=blue]
      > document.write( ""+a1+" "+a2+"");[/color]

      document.write( a1, ' ', a2);


      JW



      Comment

      Working...