Any one know how to use a duplicate javascript in the same page?

A

Amy

Hi using duplicate javascripts on the same page never work for me due
to the same property fields on the page twice. Anyone know how to get
around this? Thanks.
 
S

scriptguru

Amy said:
Hi using duplicate javascripts on the same page never work for me due
to the same property fields on the page twice. Anyone know how to get
around this? Thanks.

Can you show an example, Amy?

Val Polyakh
 
A

Amy

Gosh, most of them really. Lets say I have two identical javascripts. I
call both of them with an onload command. <script
type="text/javascript">window.onload=function(){image1();image2();}</script>Thing
is they both have identical other areas in the body section.

<a href="#" id="link" target="_blank"><img id="img" title="title"
border="0"></a>
<a href="#" id="link" target="_blank"><img id="img" title="title"
border="0"></a>

Since there are two identical slots to fill, the script doesn't know
what to do, and only one works. How to get around this problem?
Thankyou Amy
 
A

adamraney

In HTML, is you use the ID attribute on a tag, it needs to be unique.
You cannot have more than 1 element with the same ID. Here you have two
elements with id='img', which is not valid HTML. Plus, if you use
javascript's getElementById() command, it can only return 1 (I am
guessing the first one it finds).

Try using different IDs on your images and calling them appropriately.
 
A

ASM

Amy a écrit :
Gosh, most of them really. Lets say I have two identical javascripts. I
call both of them with an onload command. <script
type="text/javascript">window.onload=function(){image1();image2();}</script>Thing
is they both have identical other areas in the body section.

if you have two time same function or same mane for 2 functions
(i.e image1() ) only the second will fire
(the 1st is scratched by the 2nd)
<a href="#" id="link" target="_blank"><img id="img" title="title"
border="0"></a>
<a href="#" id="link" target="_blank"><img id="img" title="title"
border="0"></a>

Since there are two identical slots to fill, the script doesn't know
what to do, and only one works. How to get around this problem?
Thankyou Amy

Having 2 elements with same id is forbidden !

Or do you mean that
image1() write 1st link
image2() write 2nd link (exactly same as 1st)
? ? ?

Nothing very clear about what you try to do ...

have links with different ids
and function 1 for link 1 and function 2 for link 2
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,014
Latest member
BiancaFix3

Latest Threads

Top