User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the JavaScript / DHTML / AJAX section within the Web Development category of DaniWeb, a massive community of 391,774 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,440 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our JavaScript / DHTML / AJAX advertiser: Lunarpages Web Hosting
Views: 602 | Replies: 4 | Solved
Reply
Join Date: Mar 2008
Location: Lagos, Nigeria
Posts: 69
Reputation: mexabet is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 5
mexabet's Avatar
mexabet mexabet is offline Offline
Junior Poster in Training

Two Javascripts clashing on one web page.

  #1  
Apr 14th, 2008
I'm having an issue getting two Javascripts to work on one page. It seems that one disables the other and only one is working when previewed together. I know of a code that can be inserted so that both codes can function on one page, but I just can't lay my hands on it right now.

So, can anyone here provide me such code, please?
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Jan 2007
Posts: 2,510
Reputation: MidiMagic is on a distinguished road 
Rep Power: 7
Solved Threads: 103
MidiMagic's Avatar
MidiMagic MidiMagic is offline Offline
Posting Maven

Re: Two Javascripts clashing on one web page.

  #2  
Apr 14th, 2008
Several questions:

1. How are you starting the scripts? If you don't specify how they start (i.e. onclick, etc.), only the last one defined in the body tag will start.

2. Are the scripts in the header? Scripts in the header will not run until told to by a command in a tag in the body.

3. Did you think of calling one script from the other?

4. Do the scripts have some variable names in common? Make sure they do not share variable names. All global variables will keep their values from one script to the other.
Last edited by MidiMagic : Apr 14th, 2008 at 2:58 pm.
Daylight-saving time uses more gasoline
Reply With Quote  
Join Date: Oct 2005
Posts: 236
Reputation: Inny is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 5
Inny's Avatar
Inny Inny is offline Offline
Posting Whiz in Training

Re: Two Javascripts clashing on one web page.

  #3  
Apr 15th, 2008
If your codes are called at body onload, you run more than one, eg

<body onload='do this();do that()'>
add a semicolon after each command
Always carry a flagon of whiskey in case of snakebite and furthermore always carry a small snake.
W. C. Fields
Reply With Quote  
Join Date: Jun 2006
Location: India
Posts: 6,774
Reputation: ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold 
Rep Power: 23
Solved Threads: 330
Moderator
Featured Poster
~s.o.s~'s Avatar
~s.o.s~ ~s.o.s~ is offline Offline
Rebellion Revamped

Re: Two Javascripts clashing on one web page.

  #4  
Apr 15th, 2008
Or a better way would be to encapsulate all the functions which need to be executed inside a single function and call that function instead.
<body onload="doAll();">...</body>

> It seems that one disables the other and only one is working when previewed together.

We would have no way of knowing what the problem is unless you post some code or provide some more explanation.
"I don't accept change. I don't deserve to live."

"Working a real job is a win if you're lazy, greedy, or unmotivated. If you're average, you fit right in. And if you're above average, the basic terms of employment and premise of the arrangement is against your interests."
Reply With Quote  
Join Date: Mar 2008
Location: Lagos, Nigeria
Posts: 69
Reputation: mexabet is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 5
mexabet's Avatar
mexabet mexabet is offline Offline
Junior Poster in Training

Re: Two Javascripts clashing on one web page.

  #5  
Apr 15th, 2008
Thanks to all who replied. You've been helpful. The issue is now resolved.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

DaniWeb JavaScript / DHTML / AJAX Marketplace
Thread Tools Display Modes

Other Threads in the JavaScript / DHTML / AJAX Forum

All times are GMT -4. The time now is 4:49 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC