473,602 Members | 2,767 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.getEl ementById && document.getEle mentsByTagName &&
document.create TextNode) {
document.write( '<link rel="stylesheet " type="text/css"
href="portfolio _hide_links.css " />');
window.onload = initToggleCateg ories;
}

function initToggleCateg ories() {
document.getEle mentById('conte ntPool').style. display = 'none';
var as = document.getEle mentById('toggl e').getElements ByTagName('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.getEle mentById('curre nt');
// If this element exists, remove its ID attribute
if (oldCurrent) oldCurrent.remo veAttribute('id ');
// Add the ID attribute with value 'current' to the newly active tab
header (LI element)
l.parentNode.se tAttribute('id' , 'current');
var oldCloneUL = document.getEle mentById('clone UL');
if (oldCloneUL) document.body.r emoveChild(oldC loneUL);
var cloneUL = document.create Element('ul');
cloneUL.setAttr ibute('id', 'cloneUL');
document.body.a ppendChild(clon eUL);
var lis =
document.getEle mentById('conte ntPool').getEle mentsByTagName( '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.inde xOf(cat_class) != -1) {
var clone = lis[c].cloneNode(true );
// Get value of the link element
var aValue = clone.firstChil d.firstChild.no deValue;
// 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.childNo des[j] == 'undefined')
cloneUL.appendC hild(clone);
// Otherwise insert the new LI element at alphabetical order
else cloneUL.insertB efore(clone, cloneUL.childNo des[j]);
}
}
}
}
}

// 2nd script ///

if (document.getEl ementById && document.getEle mentsByTagName &&
document.create TextNode) {
document.write( '<link rel="stylesheet " type="text/css"
href="showhide. css" />');
window.onload = initShowHide;
}

function initShowHide() {
hide();
var SkillList = document.getEle mentById('Skill List');
var as = SkillList.getEl ementsByTagName ('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.getEle mentById(id).st yle.display = 'block';
}

function hide() {
var Skills =
document.getEle mentById('Skill s').getElements ByTagName('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 1935
<em***@davefink .com> wrote in message news:11******** **************@ f14g2000cwb.goo glegroups.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.getEl ementById && document.getEle mentsByTagName &&
document.create TextNode) {
document.write( '<link rel="stylesheet " type="text/css"
href="portfolio _hide_links.css " />');
window.onload = initToggleCateg ories;
}
[snip
// 2nd script ///

if (document.getEl ementById && document.getEle mentsByTagName &&
document.create TextNode) {
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.getEl ementById && document.getEle mentsByTagName &&
document.create TextNode)
{
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 ()
{
initToggleCateg ories();
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
1667
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 up and any javascript that I use a src file with <script language="javascript" src="mytest.js"></script> ) returns random errors. Javascript on the page itself works fine. If I click f5 multiple times I will get different results. I am...
2
1325
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 snippet is as follows: <form action="names.html" enctype="multipart/form-data"
2
1716
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" style="position:absolute;"></div> <script src="staticlogo.js"> </script>
2
5531
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, the system does a "doPostBack" operation. Some of my systems have no issues and work fine. Others fail and time out. I have spoke to the developer at our partners company and he believes that his app is not the culprit. There is no rhyme or reason...
21
28014
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 collation conflict between "Latin1_General_CI_AS" and "SQL_Latin1_General_CP1_CI_AS" in the equal to operation. (Microsoft SQL Server, Error: 468)
3
10733
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 strike a key I get the error. Anybody know why? <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <script language="javascript" type="text/javascript ">
13
5303
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 using the setInterval function, like this: setInterval(function () {imageFade()},10); This works fine in Firefox, but in IE 7, the flash animations slow down a lot, and the javascript fading/rotation slows down some.
14
1951
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 p {color: #0000FF;} When i try to change that text- it will not change- the text on the page that is not assigned color in the external style sheet - changes just fine. Is there a conflict or does the css load after the javascript and undo the...
9
1738
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" name="action" value="yxz">yxz </form>
5
4487
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 the user data, after that a javascript function is called to load a new video. If it wasn't for the video, then I would have used panel controls to hide/ show the content. We are using swfobject to load a series of videos on the same page, and...
0
7993
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
7920
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8404
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8268
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6730
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5440
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
2418
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1510
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1254
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.