/    Sign up×
Community /Pin to ProfileBookmark

"lightswitch" help

I’m trying to have it where a user will click on an image (image A), and a light will go on (image B will change), they will click on the same image (image A) and image B will go back to the original. Kind of like a light switch. I have tried mouseclick, but all I know how to change is that the image will change once, not change again.

Would I have to do an IF statement? Any ideas would be helpful!

to post a comment
JavaScript

8 Comments(s)

Copy linkTweet thisAlerts:
@Mr_JFeb 23.2007 — You could try something like this

[CODE]<script type="text/javascript">

function swapImg(obj){

if(obj.src.indexOf("pic1.jpg")!= -1){
obj.src="pic2.jpg"
}
else{
obj.src="pic1.jpg"
}



}
</script>

<img src="pic1.jpg" onclick="swapImg(this)">[/CODE]
Copy linkTweet thisAlerts:
@aymelekauthorFeb 27.2007 — I forgot to say that I am using an image map for one of the images. There's basically six lights that a user can click on, which will change another image below it turning on the lights. So would I have to have multiple IF statements, and how would that correlate to the image map?
Copy linkTweet thisAlerts:
@Mr_JFeb 27.2007 — Take a look at these examples one may help you out

www.huntingground.freeserve.co.uk/imagery/imgmaps/imgmap2.htm
Copy linkTweet thisAlerts:
@aymelekauthorMar 02.2007 — I looked at that webpage, but all of them were rollover examples. What I need to have it basically a multiple 'onclick' action, which I dont even know if it's possible. I have an image map, where if you click on the red button, a red light will come on another graphic with the same design as the first image. If you click on the same red button a second time, the light on the second design will go off.
Copy linkTweet thisAlerts:
@Mr_JMar 02.2007 — How is this red light generated?
Copy linkTweet thisAlerts:
@aymelekauthorMar 02.2007 — Through images. I have an image that has an image map on it. When they click on part of the image that has a red button in it, another graphic will change which will show the red light. When they click on the image map again, the image with the red light will go off. I have six different areas in the image map, which will control one other image.
Copy linkTweet thisAlerts:
@Mr_JMar 02.2007 — See if this example is on the right track

[upl-file uuid=5af1d537-8065-47e7-8b47-9a9bb95dbaec size=36kB]example.zip[/upl-file]
Copy linkTweet thisAlerts:
@aymelekauthorMar 15.2007 — Thank you so much Mr. J! That helped so very much, exactly what I was looking for. Thanks again.
×

Success!

Help @aymelek 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.8,
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,
)...