Results 1 to 6 of 6
  1. #1
    Join Date
    Feb 2010
    Posts
    67
    Plugin Contributions
    0

    Default How to put Javascript inside PHP?

    I am attempting to use a javascript effect on the product images in my site but each time I attempt to insert the code into the php it fails. Here's the original code:
    Code:
    <script language="javascript" type="text/javascript"><!--
    document.write('<?php echo '<a href="javascript:popupWindow(\\\'' . zen_href_link(FILENAME_POPUP_IMAGE, 'pID=' . $_GET['products_id']) . '\\\')">' . zen_image($products_image_medium, addslashes($products_name), MEDIUM_IMAGE_WIDTH, MEDIUM_IMAGE_HEIGHT) . '</a>'; ?>');
    //--></script>
    I don't need the javascript for the pop-up window, because I'm using a script called Shadowbox that uses a REL link inside the <a> tag to provides a popup image/ shadow rest of the page effect. I deleted the original javascript portion and attempted to include this shadowbox code:
    Code:
    rel="shadowbox[strange];options={counterType:'skip',continuous:true,animSequence:'sync'}"
    Here's what I came up with.
    Code:
    <?php
      echo '<a rel="shadowbox[strange];options={counterType:'skip',continuous:true,animSequence:'sync'}" href="' . zen_href_link(FILENAME_POPUP_IMAGE, 'pID=' . $_GET['products_id']) . '" target="_blank">' . zen_image($products_image_medium, $products_name, MEDIUM_IMAGE_WIDTH, MEDIUM_IMAGE_HEIGHT) . '</a>';
    ?>
    The page loading fails each time it gets to this code. I suspect that there's a rule for formatting php that I'm unfamiliar with that is causing the trouble. Any suggestions? Thanks.
    Brian

  2. #2
    Join Date
    Aug 2005
    Location
    Arizona
    Posts
    27,755
    Plugin Contributions
    9

    Default Re: How to put Javascript inside PHP

    Got no idea where/what file you are adding this to????

    If this is a "lightBox" effect thewn just grab one of the 3rd party modules already created for this
    Or just for your reference if different
    Zen-Venom Get Bitten

  3. #3
    Join Date
    Feb 2010
    Posts
    67
    Plugin Contributions
    0

    Default Re: How to put Javascript inside PHP

    Sorry about that, kobra. It's going in the "tpl_modules_main_product_image.php" file. I'm attempting to replace a simple javascript window popup with a different effect. I haven't looked into lightbox yet, but I'll check that out, too.

  4. #4
    Join Date
    Feb 2010
    Posts
    67
    Plugin Contributions
    0

    Default Re: How to put Javascript inside PHP

    I'm fairly sure there are syntax rules for coding php that are getting screwed up when I insert the Javascript into the php, but I don't know enough about php to figure out why it's failing. My original post has the code. Any ideas?

  5. #5
    Join Date
    Jul 2005
    Location
    Upstate NY
    Posts
    22,010
    Plugin Contributions
    25

    Default Re: How to put Javascript inside PHP

    You have single quotes inside the js/rel that are not escaped with a backslash \' .

  6. #6
    Join Date
    Feb 2010
    Posts
    67
    Plugin Contributions
    0

    Default Re: How to put Javascript inside PHP

    Perfect! Thanks for the help, gjh. Okay, so I've fixed my syntax issues, but I still don't know how to get it to spit out the link that I want. Here's my code (from templates/tpl_modules_main_product_image.php):

    Code:
    <?php echo '<a rel="shadowbox[strange];options={counterType:\'skip\',continuous:true,animSequence:\'sync\'}" href="' . zen_href_link(FILENAME_POPUP_IMAGE, 'pID=' . $_GET['products_id']) . '">' . zen_image($products_image_medium, addslashes($products_name), MEDIUM_IMAGE_WIDTH, MEDIUM_IMAGE_HEIGHT) . '</a>'; ?>
    It is putting out the following html:
    Code:
    <a rel="shadowbox[strange];options={counterType:'skip',continuous:true,animSequence:'sync'}" href="http://2600strange.com/index.php?main_page=popup_image&amp;pID=5"><img src="images/shirts/logo.jpg" alt="Logo Tee" title=" Logo Tee " width="547" height="368" /></a>
    What I'd like to do is have the src from the img tag ("images/shirts/logo.jpg") be populated as the link for the "'<a href" tag as well. Where can I edit that? Thanks for all the help so far.
    Brian

 

 

Similar Threads

  1. How can I put attribute errors into a javascript popup?
    By rkarta in forum General Questions
    Replies: 14
    Last Post: 26 Nov 2010, 12:04 PM
  2. Where should I put my php/javascript files?
    By seifer987 in forum General Questions
    Replies: 5
    Last Post: 10 Nov 2008, 08:10 AM
  3. Embedded Javascript inside an EZ-Page
    By dcarrith in forum General Questions
    Replies: 4
    Last Post: 10 Jun 2008, 04:47 AM
  4. How to put regular site javascript menu on store?
    By jrf in forum Templates, Stylesheets, Page Layout
    Replies: 5
    Last Post: 13 Feb 2007, 02:16 AM

Posting Permissions

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