/    Sign up×
Community /Pin to ProfileBookmark

no javascript, help needed

Hi,
I do not know any javascript so I’m hoping that someone here can help.

I have a script that uses two html picture tags and was wondering how can clicking on one change the other.
It’s a picture that acts as a button that changes another picture.

Here’s what I’ve gathered so far:

[CODE]<script type=”text/javascript”>
imgs=Array(“play1.png”,”play2.png”);
var x=0;

function hover()
{
x++;
if (x == imgs.length) x = 0;
imp.src = imgs[x];
}

/////////////////my attempt at putting scraps together///////
img=Array(“removed.png”);
var y=0;
function click()
{
if (y == img.length) y = 0;
imp.src = img[y];
}
/////////////////////////////////////////////

</script>

<img id=”imp” src=”play1.png”>
<img onmouseover=”hover()” onmouseout=”hover()” onmousedown=”click()” name=”button” src=”button.png”>[/CODE]

As you can see that the second image will alter the first with a hover effect. However, my sad attempt to change play1.png by clicking button.png ended in a big fat fail.
Is there a way to click button.png and change the first picture?

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@astupidnameOct 30.2009 —  imp.src = img[y];[/QUOTE]
Change that to:
document.getElementById("imp").src = img[y];
Copy linkTweet thisAlerts:
@bobocheezauthorOct 31.2009 — ok it works

I have another question though:

If there is an iframe, is there a way to change a variable that is in the code of the parent window with onClick? (specifically a css number - maybe place a javascript or php variable)

diagram:

css-height: 32

iframe: onClick=change 32 to 62

of course since javascript and iframes do not get along the onClick would be placed in the code of the page that is in the frame
×

Success!

Help @bobocheez 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.6,
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,
)...