Keyword

JavaScript Conflict - I know where, but need help fixing it!

  • tlm2021
  • tlm2021's Avatar Topic Author
  • Offline
  • New Member
More
15 years 8 months ago - 15 years 8 months ago #26026 by tlm2021
EDIT: I'm a pro user, so I moved this the appropriate board.

So I have a conflict, and I know where it is. But I don't know how to resolve it without breaking the script.

The site we're having issues on is www.hitchcarriers.com/index.php?page=shop.product_details&flypage=flypage.tpl&product_id=21&category_id=1&option=com_virtuemart&Itemid=1 .

Here's the conflicting code:
//Script for tabbed boxes on the product pages
	function hidestories() {
	var divs=document.getElementById('stories').getElementsByTagName('div');
	for (j=0; j<divs.length; j++) {
		var rE = new RegExp("(^|\\s)" + 'story' + "(\\s|$)");
		if (rE.test(divs[j].className)) {
			divs[j].style.display="none";
		}
	}
}

function stories(first) {
	var thebuttons=document.getElementById('thebuttons').getElementsByTagName('a');
	for (i=0; i<thebuttons.length; i++) {
		thebuttons[i].onclick=function() {
			hidestories();
			var thestory=(this.href).split("#",2)[1];
			document.getElementById(thestory).style.display="block";
			var active=document.getElementById('activeTab');
			active.id="";
			this.parentNode.id="activeTab";
			return false;
		}
	}

	if (first) {
		var firstone=document.getElementById('stories').firstChild;
		if (firstone.nodeType != 1) {firstone = firstone.nextSibling;}
		firstone.style.display="block";
		
		var firstlink=document.getElementById('thebuttons').firstChild;
		if (firstlink.nodeType != 1) {firstlink = firstlink.nextSibling;}
		firstlink.id="activeTab";
	}
}

window.onload=function() {
	if (document.getElementById('thebuttons')){	
		hidestories();
		stories(1);
	}
}

I can resolve the conflict by commenting out any of the following lines:
for (i=0; i<thebuttons.length; i++) {
thebuttons[i].onclick=function() {
if (first) {

If I comment out the for loop, or if statement, the conflict is resolved. But if I comment everything within the for loop or if statement, it isn't. So somehow the if statement and for loop themselves are causing the conflict. I just don't know how.

Any help would be greatly appreciated.

Please Log in or Create an account to join the conversation.


Powered by Kunena Forum