View Full Version : 2 javascripts not working in 1 page.

05-20-2009, 06:37 AM
I need two or more javascripts in one page. But the problem is that when i put one or more javascript only the last one works while others donot work. But when single all work fine. What could be the problem?

05-20-2009, 07:24 AM
try to combine the init() functions that define the two scripts into one new init(). Use alerts in each step to see where the eroor is coming from.

05-20-2009, 08:11 AM
Or ... look for one (or all) of these:

window.onload = something;
onload = something;
<body .... onload="something()">

All are the same; they refer to a variable called 'onload.'
Only one per customer.

Read this (http://www.dyn-web.com/tutorials/combine.php).

05-20-2009, 08:21 AM
This may also work but should be used when none of works
ie, document.attachEvent
ff, document.addEventListener

these will allow attach more than one even handler on a page.

Philip M
05-20-2009, 09:15 AM

It should be mentioned that another possible problem is duplication of one or more function and/or variable names between the two scripts.

05-20-2009, 01:12 PM
Thanks every body. I'll go thru all of ur steps and let u know what happened.