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?

10 Years
Discussion Span
Last Post by fxm

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.


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


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.


Thanks to all who replied. You've been helpful. The issue is now resolved.


Don't hold your breath waiting for mexabet to answer - this thread is two years old.

You might find the solution to your problem by reading the answers already given above.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.