473,700 Members | 2,664 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 1941
<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
1670
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
1334
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
1720
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
5533
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
28038
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
10736
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
5324
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
1955
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
1741
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
4488
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
9217
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9078
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...
1
8974
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8928
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
7815
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...
1
6563
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4407
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
2393
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2031
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.