SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Addict Sgt. Baboon's Avatar
    Join Date
    Dec 2002
    Posts
    396
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Help with embedding html into a script

    The following code is used with a cgi script to display a section of the website if the condition is true:

    <script type="text/javascript">
    <!-- if ('$art_field8_je$' == 'yes')
    {
    document.write('CONTENT HERE');
    } -->
    </script>

    But here is what I need to insert instead of 'CONTENT HERE':

    <p><font size="2" face="ms sans serif">Online Coupon:
    </font><font size="-1" face="Arial, Helvetica, sans-serif"><a href="javascript:;" onClick="MM_openBrWindow('http://www.finditinfindlay.com/listings/exec/search.cgi?fields=art_field14&amp;keyword=Yes&amp;fields=art_name&amp;keyword=$art_name$&amp;template=search/coupon.html','Coupon','scrollbars=yes,resizable=yes,width=550,height=350')">Click Here For Printable Coupon</a></font></p>

    Now, all the double and single quotes are giving me trouble. I tried stripping out the quotes, but that didn't work. Can someone provide me with some tips on how to get this working properly?

    Thanks in advance.

  2. #2
    &#083;itePoint Aficionado JVLB's Avatar
    Join Date
    Jan 2002
    Location
    N 44 56.537' W 123 3.683'
    Posts
    1,127
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    For the most part, use single quotes only on the outside of the block you wish to write. If you need them within the block, escape them with the backslash, as in:

    \'

    Also, within the text block, you should escape any forward slash characters used on HTML closing tags with the backslash, as well. Example:

    <span><\/span>

  3. #3
    SitePoint Wizard
    Join Date
    Jul 2003
    Location
    Kent
    Posts
    1,921
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    And if I remember right, the "content here" stuff has to be a single line.

    So I cheat. I declare a number of variables = item1, item2, item3 etc, and set
    the html for about one line's worth to item1, then the next line's worth to item2
    and so on.

    Then it's document.write (item1 + item2 +item3 etc)

    I found this very handy when making a simple menu that had five to seven lines
    of html to be written, as I could just add a new itemX or delete or edit an
    existing one, knowing that if it went wrong it had to be that one line of html I
    had just altered. If you see what I mean.

  4. #4
    SitePoint Evangelist
    Join Date
    Sep 2003
    Location
    San Diego, CA
    Posts
    591
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    or even easier...
    Code:
    CntToWrt='line1'
    CntToWrt+='line2'
    CntToWrt+='line3'
    CntToWrt+='line4'
    just add as many
    Code:
    CntToWrt+='line4'
    as needed! Then at the end you can use
    Code:
    document.write(CntToWrt);

  5. #5
    &#083;itePoint Aficionado JVLB's Avatar
    Join Date
    Jan 2002
    Location
    N 44 56.537' W 123 3.683'
    Posts
    1,127
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Actually, you can concatenate lines within a block of document.write() text this way:

    document.write('<tags>and stuff<\/tags><moretags with="attributes" in="name" value="pairs">'+
    'and more stuff<\/moretags>');

    The problem, if you don't use the concatenation operator at the line end, is that JavaScript does its automatic line ending stunt, inserting the ";" for you. And they say forgiving is good. Piffle. Piffle, I say.


Bookmarks

Posting Permissions

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