Results 1 to 5 of 5
  1. #1
    Join Date
    Aug 2008
    Posts
    50
    Plugin Contributions
    0

    Default Javascript onclick redirects to homepage

    Hi all,

    Firstly not sure if this is the right section to ask this so don't shoot me.

    I'm just having a problem getting a celendar to work on my product page using the code below

    '
    <DIV ID="testdiv1" STYLE="position:absolute;visibility:hidden;background-color:white;layer-background-color:white;"></DIV>
    <SCRIPT LANGUAGE="JavaScript" ID="js18">
    var cal18 = new CalendarPopup("testdiv1");
    cal18.setCssPrefix("TEST");
    </SCRIPT>
    <INPUT TYPE="text" onClick="cal18.select(document.forms[0].date18,'anchor18','MM/dd/yyyy'); return false;" NAME="date18" VALUE="" SIZE=25>


    <A HREF="#" onClick="cal18.select(document.forms[0].date18,'anchor18','MM/dd/yyyy'); return false;" TITLE="cal18.select(document.forms[0].date18,'anchor1x','MM/dd/yyyy'); return false;" NAME="anchor18" ID="anchor18">select</A>'

    Basically clicking it redirects to the homepage. The js needed is in the product_info folder. The code works fine when in a blank php file.

    I've tried including this as an iframe which works but the popup anchor is only shown in the iframe which makes the popup cause you to scroll the iframe. Not sure of a way of moving the anchor which is uses to position the popup outside of the frame, i.e on the product page. (this is the js code I'm using - http://www.mattkruse.com/javascript/...ct_source.html)

    Hope someone has some suggestions.

    Thanks!

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

    Default Re: Javascript onclick redirects to homepage

    There's a lot not to like here, such as upper case tags and attributes (not valid XHTML), inline styling (mixing content and presentation) and an invalid language attribute value.

    However, the most likely to be causing your problem is that the form index has been hardcoded to be 0. Therefore the script will only work if there no forms already on the page when the script is first run to (I assume add the form to which the link is guided).

    This will not be the case on the product page (or indeed most Zen Cart pages) as they typically have a number of forms e.g. the search box, and in the case of the product page, all the attributes and add to cart fields are inside a form.
    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
    Aug 2008
    Posts
    50
    Plugin Contributions
    0

    Default Re: Javascript onclick redirects to homepage

    Thanks kuroi for the quick response. What you said all makes sense, the likely cause is the form being defaulted to 0, going to try changing it to something else within the html, if it is used throughout the js would a simple find and replace work?

    Thanks

  4. #4
    Join Date
    Aug 2008
    Posts
    50
    Plugin Contributions
    0

    Default Re: Javascript onclick redirects to homepage

    OK tried changinf the value in the HTML to (document.forms[2] but it still doesnt work. Also cant find any similar references in the js. Any other thoughts?

  5. #5
    Join Date
    Aug 2008
    Posts
    50
    Plugin Contributions
    0

    Default Re: Javascript onclick redirects to homepage

    Ok I'm happy now, instead of changing the id to 2 I should have tried 1 which works!

    Thanks alot!

 

 

Similar Threads

  1. Replies: 3
    Last Post: 17 Jan 2011, 05:15 PM
  2. htaccess and Simple SEO redirects not showing homepage
    By sports guy in forum All Other Contributions/Addons
    Replies: 2
    Last Post: 15 Sep 2010, 04:47 AM
  3. Homepage instantly redirects to product page - not sure why
    By creativearc in forum Customization from the Admin
    Replies: 6
    Last Post: 17 Oct 2007, 07:47 PM
  4. Installation redirects to homepage
    By dilate in forum Installing on a Windows Server
    Replies: 9
    Last Post: 25 Apr 2007, 04:28 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