Page 1 of 2 12 LastLast
Results 1 to 10 of 16
  1. #1
    Join Date
    Oct 2007
    Posts
    106
    Plugin Contributions
    0

    Default JavaScript on product page problems

    I wanted to add the script below to a product page...and it works find when in "preview" mode but doesn't work on the live site found here:

    http://www.vinashcoaching.com/store/...roducts_id=180

    Does anyone have any idea?



    Code:
    html>
    <head>
    <script language="javascript">
    var imgMax = new Image(10,10);
    imgMax.src = 'images/max_arrow.gif';
    var imgMin = new Image(10,10);
    imgMin.src = 'images/min_arrow.gif';
    function dyntog(a,thisimg)
    {
       if(a.style.display=="none")
       {
          a.style.display="inline";
          thisimg.src=imgMax.src;
       }
       else if(a.style.display=="inline")
       {
          a.style.display="none";
          thisimg.src=imgMin.src;
       }
       return false;
    }
    </script>
    <title>Expand/Collapse the table using DIV</title>
    </head>
    <body>
    <img src="max_arrow.gif" width="10" height="10" border="0" align="absmiddle" style="cursor:hand" onclick="dyntog(tbltog_1,this)" title="Click to Minimize/Maximize the table">
    <span id="tbltog_1" style="display:inline">First Line<BR>Second Line<BR></span>
    </body>
    </html>

  2. #2
    Join Date
    Apr 2006
    Location
    London, UK
    Posts
    10,569
    Plugin Contributions
    25

    Default Re: JavaScript on product page problems

    Your page structure is corrupt. You've taken the test page and just dropped it into the middle of your Zen Cart page, but you can't do this as the html tag was already open and re-opening it is an error, and you can't have two head tags.

    In addition you have a ton of unrelated validation errors that corrupt the pages structure and could also make it more difficult to javascript to work out which elements they are supposed to be working on.
    Kuroi Web Design and Development | Twitter

    (Questions answered in the forum only - so that any forum member can benefit - not by personal message)

  3. #3
    Join Date
    Oct 2007
    Posts
    106
    Plugin Contributions
    0

    Default Re: JavaScript on product page problems

    is there another code I can use to accomplish the same thing? As far as all the things that are broken, I tried to fix some of them, but the ones I didn't are a product of my lack of programming knowledge hehe, so any help here would be great...especially if I have to go edit the .css doc.

    Zidain

  4. #4
    Join Date
    Apr 2006
    Location
    London, UK
    Posts
    10,569
    Plugin Contributions
    25

    Default Re: JavaScript on product page problems

    A quick glance at that code suggests that it should do the job, but it is actually two pieces of code, one of which needs to be called in your Zen Cart page's header file and two lines that need to be inserted into the body of the page.

    Ideally you would place the javascript (the bit BETWEEN the script tags) in a file called jscript_{unique_name}.js (where {unique_name} can be anything you want). Then you place this file in your /includes/modules/pages/product_info/ folder and the javascript will be loaded automatically whenever this page is run.

    Then you place the two lines between the body tag into your tpl_product_info_default.php file which is probably what you did with the code before.
    Kuroi Web Design and Development | Twitter

    (Questions answered in the forum only - so that any forum member can benefit - not by personal message)

  5. #5
    Join Date
    Oct 2007
    Posts
    106
    Plugin Contributions
    0

    Default Re: JavaScript on product page problems

    kuroi, thanks a lot for spending the time to go through it...I actually found a code which was more simple...here is it posted below for anyone that wants it...


    The following goes in tpl_header.php
    <script langauge="JavaScript" type="text/javascript"> function doMenu(item) { obj=document.getElementById(item); col=document.getElementById("x" + item); if (obj.style.display=="none") { obj.style.display="block"; col.innerHTML="[-]"; } else { obj.style.display="none"; col.innerHTML="[+]"; } } </script>
    The following goes in the body of the prodcut desc pages (where you put in the content)
    <a href="javascript:doMenu('main');" id=xmain>[+]</a> Main Item <div id=main style="margin-left:1em"> <a href=#>Item 1</a><br> <a href=#>Item 2</a><br> <a href=#>Item 3</a> </div> <br>
    The only thing I can't figure out is how to increase the table from 3 lines to more...to work around this as you can see on http://www.vinashcoaching.com/store/...roducts_id=180 I just added all the FAQ's to the first Item line, although it causes a weird indent in the content. Does anyone know how to increase the lines?

    Also I got the code from here
    http://www.##########################/code/67426-j...-collapse.html
    ...want to give the guy that wrote it the credit
    Zidain

  6. #6
    Join Date
    Apr 2006
    Location
    London, UK
    Posts
    10,569
    Plugin Contributions
    25

    Default Re: JavaScript on product page problems

    Although that will work, it's rather illogical. I think you're confusing the visible header on the screen (which is controlled by tpl_header.php) with the page's html header (which is where you should really place your javascript).

    If you wanted to force it in by brute force, then the appropriate place would be the html_header.php file.

    But this would have the disadvantage of including it for every page, even when it's not needed. This is why I showed you the proper Zen Cart way to load your javascript for a specific page, which is still applicable to your new code.
    Kuroi Web Design and Development | Twitter

    (Questions answered in the forum only - so that any forum member can benefit - not by personal message)

  7. #7
    Join Date
    Oct 2007
    Posts
    106
    Plugin Contributions
    0

    Default Re: JavaScript on product page problems

    Can you do me a favor and tell me the exact steps I need to take now that I have it in the wrong place in order to put it in the right one...I'm kinda new at this and don't want to bog it up. Thanks.

    Zidain~

  8. #8
    Join Date
    Oct 2007
    Posts
    106
    Plugin Contributions
    0

    Default Re: JavaScript on product page problems

    this is another code I wanted to add...can you walk me through the specific steps...

    <SCRIPT LANGUAGE="JavaScript">
    <!-- Begin
    function popUp(URL) {
    day = new Date();
    id = day.getTime();
    eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=200,h eight=300');");
    }
    // End -->
    </script>


    <A HREF="javascriptopUp('http://www.vinashcoaching.com/pages/icupfaq.php')">Open the Popup Window</A>

  9. #9
    Join Date
    Apr 2006
    Location
    London, UK
    Posts
    10,569
    Plugin Contributions
    25

    Default Re: JavaScript on product page problems

    Quote Originally Posted by zidain View Post
    this is another code I wanted to add...can you walk me through the specific steps...
    I suggest re-reading post #4 where I do exactly this.
    Kuroi Web Design and Development | Twitter

    (Questions answered in the forum only - so that any forum member can benefit - not by personal message)

  10. #10
    Join Date
    Oct 2007
    Posts
    106
    Plugin Contributions
    0

    Default Re: JavaScript on product page problems

    Well here is what I did with this code...and sorry for being such a noob here but I do want to get this right...


    I took the quote below and created a file named:
    jscript_header.js and placed it in the following directory:
    /includes/modules/pages/product_info/

    <SCRIPT LANGUAGE="JavaScript">
    <!-- Begin
    function popUp(URL) {
    day = new Date();
    id = day.getTime();
    eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,men ubar=0,resizable=1,width=200,height=300');");
    }
    // End -->
    </script>
    Then I took the following code and put in into the HTML editor on the product page in the admin tool ...

    <A HREF="javascriptopUp('http://www.vinashcoaching.com/pages/icupfaq.php')">Open the Popup Window</A>

    Here is the page live: http://www.vinashcoaching.com/store/...roducts_id=180

    as you can see this code isn't working...so what am I doing wrong? Sorry for being so noobie hehe

    Thanks for your help and patience kuroi.

    Zidain~

 

 
Page 1 of 2 12 LastLast

Similar Threads

  1. Help a newbie install a piece of javascript with product vars on a product page
    By jhkaplan in forum Templates, Stylesheets, Page Layout
    Replies: 18
    Last Post: 1 May 2012, 05:35 PM
  2. Problems integrating php/javascript on main page
    By webrock in forum Templates, Stylesheets, Page Layout
    Replies: 0
    Last Post: 23 Jan 2009, 05:20 AM
  3. Add JavaScript to one product page
    By jeking in forum Templates, Stylesheets, Page Layout
    Replies: 5
    Last Post: 26 Feb 2008, 08:26 PM
  4. how do I add a javascript in product page
    By reza in forum Contribution-Writing Guidelines
    Replies: 0
    Last Post: 31 May 2007, 11:54 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