Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsGeneralPHPASPPerlColdFusionFlashHTML, CSS, ScriptsBrowsers

Webmaster Forum / HTML, CSS, Scripts / JavaScript / October 2006



Tip: Looking for answers? Try searching our database.

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

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Amy - 31 Oct 2006 13:37 GMT
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.
scriptguru@gmail.com - 31 Oct 2006 13:45 GMT
> 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
Amy - 31 Oct 2006 15:32 GMT
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

> > 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
[quoted text clipped - 3 lines]
>
> Val Polyakh
adamraney@gmail.com - 31 Oct 2006 19:05 GMT
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.

> Gosh, most of them really. Lets say I have two identical javascripts. I
> call both of them with an onload command. <script
[quoted text clipped - 18 lines]
>
> > Val Polyakh
ASM - 01 Nov 2006 00:29 GMT
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>
[quoted text clipped - 4 lines]
> 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
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.