/    Sign up×
Community /Pin to ProfileBookmark

Rollover failure when adding more than one to page

Trying to get 6 rollover buttons (three-state: link, hover, click) on same page (not published yet – no url). I’m not a programmer, so I found some code off of a tutorial page that works great. Problem is, I can only get it to work on the first button (all buttons are exactly the same, and use the same three source-images). What I tried was to simply copy and paste the <a href> material from the first button, and apply to the second button’s location. The effect of this was that neither the first nor the second would work. FYI – I’m testing the code on IE 6 and Opera 7.5. How do I alter the code and html to get all 6 buttons to look and function exactly the same? Here’s the code that works for the first button:

<SCRIPT Language=”JavaScript”>
<!–
// Load images for menu
var button1
var button2
var button3
if(document.images){
button1 = new Image(45,45)
button2 = new Image(45,45)
button3 = new Image(45,45)
button1.src = “images/button1.jpg”
button2.src = “images/button2.jpg”
button3.src = “images/button3.jpg”
}
//–>
</SCRIPT>


———————————————

<A HREF=”about.html”
onMouseOver=”document.button.src=button2.src”
onMouseDown=”document.button.src=button3.src”
onMouseOut=”document.button.src=button1.src”>
<IMG src=”images/button1.jpg” align=”absmiddle” border=”0″ name=”button” /></A>

Thanks for your time! ~simplifye

to post a comment
JavaScript

5 Comments(s)

Copy linkTweet thisAlerts:
@phpnoviceMar 04.2006 — Change the name of your IMG tag's NAME attribute with each copy of this code.
Copy linkTweet thisAlerts:
@simplifyeauthorMar 04.2006 — Change the name of your IMG tag's NAME attribute with each copy of this code.[/QUOTE]

Thanks phpnovice - One more thing: Does it matter what name I assign the new NAME attribute, or do I just make up something that's different from the rest? Also, do I have to then make a change to the script between the <head> tags? Thanks, ~simplifye
Copy linkTweet thisAlerts:
@LeruraMar 04.2006 — you can use whatever name you want; except for the names of the images(button1,button2,button3), and you do not have to change the script if it is the same images that you use for all the links

but i will suggest that you move the onmouse commands to the img and

rewrite them to [COLOR=Blue]this[/COLOR].src="button1.src"
Copy linkTweet thisAlerts:
@simplifyeauthorMar 05.2006 — It Works! Thanks phpnovice & Lerura - I really appreciate the help. Here's an example of the corrected code if anyone else encounters the same problem -

<SCRIPT Language="JavaScript">

<!--

// Load images for menu

var button1

var button2

var button3

if(document.images){

button1 = new Image(45,45)

button2 = new Image(45,45)

button3 = new Image(45,45)

button1.src = "images/button1.jpg"

button2.src = "images/button2.jpg"

button3.src = "images/button3.jpg"

tnr1 = new Image(45,45)

tnr2 = new Image(45,45)

tnr3 = new Image(45,45)

tnr1.src = "images/button1.jpg"

tnr2.src = "images/button2.jpg"

tnr3.src = "images/button3.jpg"

sp1 = new Image(45,45)

sp2 = new Image(45,45)

sp3 = new Image(45,45)

sp1.src = "images/button1.jpg"

sp2.src = "images/button2.jpg"

sp3.src = "images/button3.jpg"

es1 = new Image(45,45)

es2 = new Image(45,45)

es3 = new Image(45,45)

es1.src = "images/button1.jpg"

es2.src = "images/button2.jpg"

es3.src = "images/button3.jpg"

}

//-->

</SCRIPT>

Then, in the a href part, after "name," insert the correct reference (without the number - in this example it is either "button," "tnr," ""sp," or "es.") Hope this proves helpful to someone someday!
Copy linkTweet thisAlerts:
@phpnoviceMar 05.2006 — There was no need to duplicate those images so many times. You just had to do this:
<i>
</i>&lt;A HREF="about.html"&gt;&lt;IMG
src="images/button1.jpg" align="absmiddle" border="0"
onMouseOver="this.src=button2.src"
onMouseDown="this.src=button3.src"
onMouseOut="this.src=button1.src" /&gt;&lt;/A&gt;

&lt;A HREF="products.html"&gt;&lt;IMG
src="images/button1.jpg" align="absmiddle" border="0"
onMouseOver="this.src=button2.src"
onMouseDown="this.src=button3.src"
onMouseOut="this.src=button1.src" /&gt;&lt;/A&gt;

&lt;A HREF="contacts.html"&gt;&lt;IMG
src="images/button1.jpg" align="absmiddle" border="0"
onMouseOver="this.src=button2.src"
onMouseDown="this.src=button3.src"
onMouseOut="this.src=button1.src" /&gt;&lt;/A&gt;
×

Success!

Help @simplifye spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.24,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...