Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Need help with Javascript for OSC


knipper

Recommended Posts

Hi All,

 

I am using an external javascript file (and old version of STS) The script to to change text in a href link. It is only used on Catalog Category and product pages. The script itself is working when used. However... on other pages where the link is not used, it shows a javascript error icon (in the browser tray).

 

As writing the post, I remembered I could just put the script on the product_info.php for use on that page... but doesn't index.php control the categories display?

 

Here is the external javascript code, and the div that activates it

// here is the javascript

function toggle(el)
{
myEl = document.getElementById(el);
myEl.style.display = (myEl.style.display == 'none') ? 'block' : 'none';
}
window.onload = function(){ 
toggle('a'); 
} 

// Here is the link

<div id="show" style="display: block"><span onclick="toggle('show');toggle('hide');toggle('a');">Show the new link</span></div>
<div id="hide" style="display: none"><span onclick="toggle('show');toggle('hide');toggle('a');">Show the old link</span></div>
<div id="a">Here is the shown information. You should have needed to click the Show the new link above to see this.</div>

 

If it can't be placed on the index page... I think it just need an IF ELSE statement to stop throwing errors on pages that don't use the links.

 

Thanks in advance to anyone who can help! :)

Steve K AKA - Knipper -

Link to comment
Share on other sites

After getting some sleep, and taking a look again at the code...

 

I think it is the *window.onload = function(){* that is causing the problem. This forces a div element in css to load correctly. But the pages that don't use that element are getting the error.

 

Can someone help a non-javascript guy out?

 

The whole code is shown in the original post. :blink:

Steve K AKA - Knipper -

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...