473,383 Members | 1,859 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

Javascript conflict - culprit

I'm trying to combine these two scripts to acomplish a combined effect.
None of my variables are duplicates so that's not the problem. I've
been able to identify the line that breaks the first script - however I
don't know how to fix it. Both scripts work great separately. When I
comment out the 1 line in the 2nd script the 1st script works. And when
I leave the comment out the second one works but not the first. Please
HELP!

// 1st script ///
if (document.getElementById && document.getElementsByTagName &&
document.createTextNode) {
document.write('<link rel="stylesheet" type="text/css"
href="portfolio_hide_links.css" />');
window.onload = initToggleCategories;
}

function initToggleCategories() {
document.getElementById('contentPool').style.displ ay = 'none';
var as = document.getElementById('toggle').getElementsByTag Name('a');
for (var i = 0; i < as.length; i++) {
as[i].onclick = function() {
toggle(this);
return false;
}
}
// Activate the first tab by default
toggle(as[0]);
}

function toggle(l) {
// Try to get a reference to an element with the id 'current' (a
previously active tab header)
var oldCurrent = document.getElementById('current');
// If this element exists, remove its ID attribute
if (oldCurrent) oldCurrent.removeAttribute('id');
// Add the ID attribute with value 'current' to the newly active tab
header (LI element)
l.parentNode.setAttribute('id', 'current');
var oldCloneUL = document.getElementById('cloneUL');
if (oldCloneUL) document.body.removeChild(oldCloneUL);
var cloneUL = document.createElement('ul');
cloneUL.setAttribute('id', 'cloneUL');
document.body.appendChild(cloneUL);
var lis =
document.getElementById('contentPool').getElements ByTagName('li');
var cat_class = l.getAttribute('href').match(/#(\w.+)/)[1];
// Create helper array for sorting elements on alphabetical order
var tmpSort = new Array();
for (var c = 0; c < lis.length; c++) {
if (lis[c].className.indexOf(cat_class) != -1) {
var clone = lis[c].cloneNode(true);
// Get value of the link element
var aValue = clone.firstChild.firstChild.nodeValue;
// Add this value to the helper Array; Note that we cannot use
Array.push(), because older browsers like IE5 don't support it
tmpSort[c] = aValue;
// Sort the helper Array on alphabetical order
tmpSort.sort();
// Check what the new position of the element should be
for (var j = 0; j < tmpSort.length; j++) {
if (tmpSort[j] == aValue) {
// If the new LI element should be appended at a new position,
append it
if (typeof cloneUL.childNodes[j] == 'undefined')
cloneUL.appendChild(clone);
// Otherwise insert the new LI element at alphabetical order
else cloneUL.insertBefore(clone, cloneUL.childNodes[j]);
}
}
}
}
}

// 2nd script ///

if (document.getElementById && document.getElementsByTagName &&
document.createTextNode) {
document.write('<link rel="stylesheet" type="text/css"
href="showhide.css" />');
window.onload = initShowHide;
}

function initShowHide() {
hide();
var SkillList = document.getElementById('SkillList');
var as = SkillList.getElementsByTagName('a');
for (var b = 0; b < as.length; b++) {
as[b].onmouseover = function() {show(this); return false; }
as[b].onfocus = function() {show(this); return false; }
}
}

function show(s) {
hide();
var id = s.href.match(/#(\w.+)/)[1];
document.getElementById(id).style.display = 'block';
}

function hide() {
var Skills =
document.getElementById('Skills').getElementsByTag Name('div');

//////// THIS LINE BELOW IS WHAT BREAKS SCRIPT #1
for (var i = 0; i < Skills.length; i++) {
//////// THIS LINE ABOVE IS WHAT BREAKS SCRIPT #1

Skills[i].style.display = 'none';
}
}

Oct 21 '05 #1
3 1920
<em***@davefink.com> wrote in message news:11**********************@f14g2000cwb.googlegr oups.com...
I'm trying to combine these two scripts to acomplish a combined effect.
None of my variables are duplicates


except for(var i...

Assuming both run sumultaneously, that could be the problem.
--
S.C.
Oct 21 '05 #2

em***@davefink.com wrote:
I'm trying to combine these two scripts to acomplish a combined effect.
None of my variables are duplicates so that's not the problem. I've
been able to identify the line that breaks the first script - however I
don't know how to fix it. Both scripts work great separately. When I
comment out the 1 line in the 2nd script the 1st script works. And when
I leave the comment out the second one works but not the first. Please
HELP!

// 1st script ///
if (document.getElementById && document.getElementsByTagName &&
document.createTextNode) {
document.write('<link rel="stylesheet" type="text/css"
href="portfolio_hide_links.css" />');
window.onload = initToggleCategories;
}
[snip
// 2nd script ///

if (document.getElementById && document.getElementsByTagName &&
document.createTextNode) {
document.write('<link rel="stylesheet" type="text/css"
href="showhide.css" />');
window.onload = initShowHide;
}

[snip]

This is where the problem lies:
window.onload = ...

If you're trying to combine both scripts, then the 2nd script will
override the 1st script's initial assignment to the window.onload
event. Thus only calling one of the init function not both. To fix,
replace the above into one as follows:

if (document.getElementById && document.getElementsByTagName &&
document.createTextNode)
{
document.write('<link rel="stylesheet" type="text/css"
href="portfolio_hide_links.css" />');
document.write('<link rel="stylesheet" type="text/css"
href="showhide.css" />');

window.onload = function ()
{
initToggleCategories();
initShowHide();
}
}

Oct 21 '05 #3
Thank you "web.dev" it's people like you that make the world a better
place. Worked like a charm. :)

Thank you!
DF

Oct 25 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Jason | last post by:
I have two applications that I wrote that use asp and javascript source files. Recently both of these applications starting acting strange on my test box. Image icons will randomly stop showing...
2
by: Slav | last post by:
Hello, I'm trying to put a menu on a page containing a select form. The code for the menu I took from http://dynamicdrive.com/dynamicindex1/topnavbar.htm and the form is in the code...
2
by: loquini | last post by:
Hi, I'm using this piece of code, both scripts work fine separately but together only works the second one, How can I solve this conflict??? plss help me <body> <div id="watermarklogo"...
2
by: DSipp | last post by:
First, I am not a developer. My company works with a partner. This partner has a web app that we interact with. All of my systems can connect and login to this site. When we select an issue link,...
21
by: Peter Nurse | last post by:
I have just upgraded to SQL Server 2005 from SQL Server 2000. In Microsoft SQL Server Management Studio, when I click on database properties, I receive the following error:- Cannot resolve the...
3
by: jason | last post by:
I have a very simple asp.net 2.0 page with one textbox that onkeyPress is suppose to do some check of what was typed. Below is the source showing the javascript function is available. The minute I...
13
by: mudgen | last post by:
I have a webpage that has two flash animations running. I also have a javascript script running that rotates 3 images and fades them in and out. To do the fading and rotating in javascript I am...
14
Webwench
by: Webwench | last post by:
I am trying to run a simple script- (I'm just learning javascrpt) that uses a set of buttons to change the background and foreground colors of a web page. Some of the text on the page uses the css...
9
by: Meendar | last post by:
Hi, Below is my code snippet having only one form, <form> <input type ="radio" name="action" value="xyz" checked>xyz <input type ="radio" name="action" value="zyx">zyx <input type ="radio"...
5
by: voidinutah | last post by:
Hello, I'm new to .NET and was trying to find a solution for having a button control do a post back then execute a javascript function. When the button is clicked a post back occurs to save...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.