Closed Thread Icon

Topic awaiting preservation: I can't even create a rollover script! Pages that link to <a href="https://ozoneasylum.com/backlink?for=8336" title="Pages that link to Topic awaiting preservation: I can&amp;#039;t even create a rollover script!" rel="nofollow" >Topic awaiting preservation: I can&#039;t even create a rollover script!\

 
Author Thread
sonicsnail
Bipolar (III) Inmate

From: Scotland
Insane since: Jun 2001

posted posted 10-07-2002 11:33

Whats wrong with this??

the idea being that imageA appears first, then onclick imageB appears, and onclick again, imageA appears. No mousevers,mouseouts, etc, just clickys! (I'm going to give a variable a value on each click too.. but I'll add that once I get the changing image working!)

Getting the syntax wrong though :-(

code:
<html>
<head>

<script language="JavaScript1.1">

function ChangeIt() {

if (document.images["Image1"].src="choose_B.gif")
then {
document.images["Image1"].src="choose_A.gif"}
else {
document.images["Image1"].src="choose_B.gif"
}
}

</script>
</head>
<body>

<a href="#" onclick="ChangeIt();">
<img src="choose_A.gif" name="Image1" border=0>
</a>

</body>
</html>



GRUMBLE
Paranoid (IV) Mad Scientist

From: Omicron Persei 8
Insane since: Oct 2000

posted posted 10-07-2002 11:42

i don know if onlcick works in most browsers, but it should.

anyways i think your code should look like this:

document.images.Image1.src
or
document.images[0].src

InI
Paranoid (IV) Mad Scientist

From: Somewhere over the rainbow
Insane since: Mar 2001

posted posted 10-07-2002 12:02

The poster has demanded we remove all his contributions, less he takes legal action.
We have done so.
Now Tyberius Prime expects him to start complaining that we removed his 'free speech' since this message will replace all of his posts, past and future.
Don't follow his example - seek real life help first.

sonicsnail
Bipolar (III) Inmate

From: Scotland
Insane since: Jun 2001

posted posted 10-07-2002 12:07

Thanks,

I added the extra "=" and I get "object expected"error (IE5)

???

Pete

mr.maX
Maniac (V) Mad Scientist

From: Belgrade, Serbia
Insane since: Sep 2000

posted posted 10-07-2002 12:11

There is no "then" statement in JavaScript.

if (document.images["Image1"].src="choose_B.gif")
then {
document.images["Image1"].src="choose_A.gif"}

Therefore, you should remove it...


sonicsnail
Bipolar (III) Inmate

From: Scotland
Insane since: Jun 2001

posted posted 10-07-2002 12:26

Still no joy, even without the "then"..

code:
function ChangeIt() {

if (document.images["Image1"].src=="choose_B.gif")
document.images["Image1"].src="choose_A.gif"}
else {
document.images["Image1"].src="choose_B.gif"
}
}



[This message has been edited by sonicsnail (edited 10-07-2002).]

GRUMBLE
Paranoid (IV) Mad Scientist

From: Omicron Persei 8
Insane since: Oct 2000

posted posted 10-07-2002 12:29

just out of curiosity:
also if my version is wrong, did you try it? cause i feel lucky.

sonicsnail
Bipolar (III) Inmate

From: Scotland
Insane since: Jun 2001

posted posted 10-07-2002 12:30

sorry Grumble.. same error.

Pete

InI
Paranoid (IV) Mad Scientist

From: Somewhere over the rainbow
Insane since: Mar 2001

posted posted 10-07-2002 12:37

The poster has demanded we remove all his contributions, less he takes legal action.
We have done so.
Now Tyberius Prime expects him to start complaining that we removed his 'free speech' since this message will replace all of his posts, past and future.
Don't follow his example - seek real life help first.

GRUMBLE
Paranoid (IV) Mad Scientist

From: Omicron Persei 8
Insane since: Oct 2000

posted posted 10-07-2002 12:42

pete, i just tested your code myself and i found out, that it doesnt work, because it cant test for the source.
so the if-statement doesnt really work.

do you really need it? i mean you know anyways which sourcefile the image has at the beginning.

sonicsnail
Bipolar (III) Inmate

From: Scotland
Insane since: Jun 2001

posted posted 10-07-2002 12:49

ok.. getting warm!

example so far

but it only changes one way! try it!

fun eh..

Pete



[This message has been edited by sonicsnail (edited 10-07-2002).]

GRUMBLE
Paranoid (IV) Mad Scientist

From: Omicron Persei 8
Insane since: Oct 2000

posted posted 10-07-2002 12:58

yes, that's because the if-statement doesnt work.
and the else is directly executed.

sonicsnail
Bipolar (III) Inmate

From: Scotland
Insane since: Jun 2001

posted posted 10-07-2002 12:59

Grumble, I was writing my last reply when yours must have appeared.

Yes, I need this kind of functionallity.. I assumed the if/else thing was the way to do it.. how else can I achieve the same effect?

cheers,

Pete.

::EDIT:: - you pre-posted me again!

[This message has been edited by sonicsnail (edited 10-07-2002).]

InI
Paranoid (IV) Mad Scientist

From: Somewhere over the rainbow
Insane since: Mar 2001

posted posted 10-07-2002 13:10

The poster has demanded we remove all his contributions, less he takes legal action.
We have done so.
Now Tyberius Prime expects him to start complaining that we removed his 'free speech' since this message will replace all of his posts, past and future.
Don't follow his example - seek real life help first.

GRUMBLE
Paranoid (IV) Mad Scientist

From: Omicron Persei 8
Insane since: Oct 2000

posted posted 10-07-2002 13:12

maybe with a variable switching from true to false;

set this in the body or after the JS-function in the script.
onload="switcher=true;"

then in your if statement:
if (switcher==true){
document.images["Image1"].src="choose_A.gif";
switcher=false;
} else {
document.images["Image1"].src="choose_B.gif";
switcher=true;
}


edit: damn, ini was faster! i should improve my typing speed.


[This message has been edited by GRUMBLE (edited 10-07-2002).]

sonicsnail
Bipolar (III) Inmate

From: Scotland
Insane since: Jun 2001

posted posted 10-07-2002 13:38

Hurray...

thanks chaps.. it works!

My (wrong) assumption was that when you change the src in the js, it would "remember" that for next time...

live'n'learn eh!

They say "you learn something new every day" - I say "I learn something new every 2 minutes"!

thanks again,

Pete

« BackwardsOnwards »

Show Forum Drop Down Menu