Connecting Tech Pros Worldwide Forums | Help | Site Map

How Do I Change to OnClick?

Jenny
Guest
 
Posts: n/a
#1: Sep 19 '05
Hi - There's a neat little snowfall effect at
http://javascript.internet.com/bgeffects/snow.html. I want to use it for a
school project, but I need to run it by clicking on a button, rather than
when the page loads. In the HTML, I want to use something like:

<FORM>
<INPUT TYPE="button" value="Winter Time" onClick="?????">
</FORM>

but I cannot figure out what to do with the actual script to make this work.
I'd appreciate any suggestions. BTW, I'm a serious novice, so please keep it
as simple as possible. Thank you.
Jenny



ASM
Guest
 
Posts: n/a
#2: Sep 19 '05

re: How Do I Change to OnClick?


Jenny wrote:[color=blue]
> Hi - There's a neat little snowfall effect at
> http://javascript.internet.com/bgeffects/snow.html. I want to use it for a
> school project, but I need to run it by clicking on a button, rather than
> when the page loads. In the HTML, I want to use something like:[/color]

you delete :

if (ns4up) {
snowNS();
} else if (ie4up) {
snowIE();
}

from the script

and enter it in your onclick

onclick="if(ns4up) snowNS(); else if(ie4up) snowIE();"

[color=blue]
> <FORM>
> <INPUT TYPE="button" value="Winter Time" onClick="?????">
> </FORM>
>
> but I cannot figure out what to do with the actual script to make this work.
> I'd appreciate any suggestions. BTW, I'm a serious novice, so please keep it
> as simple as possible. Thank you.
> Jenny
>
>[/color]


--
Stephane Moriaux et son [moins] vieux Mac
McKirahan
Guest
 
Posts: n/a
#3: Sep 19 '05

re: How Do I Change to OnClick?


"Jenny" <jwilliams64@earthlink.net> wrote in message
news:aRzXe.64253$SL.996468@twister.southeast.rr.co m...[color=blue]
> Hi - There's a neat little snowfall effect at
> http://javascript.internet.com/bgeffects/snow.html. I want to use it for a
> school project, but I need to run it by clicking on a button, rather than
> when the page loads. In the HTML, I want to use something like:
>
> <FORM>
> <INPUT TYPE="button" value="Winter Time" onClick="?????">
> </FORM>
>
> but I cannot figure out what to do with the actual script to make this[/color]
work.[color=blue]
> I'd appreciate any suggestions. BTW, I'm a serious novice, so please keep[/color]
it[color=blue]
> as simple as possible. Thank you.
> Jenny[/color]

Place this (exisiting) code in a function:

if (ns4up) {
snowNS();
} else if (ie4up) {
snowIE();
}

Then have a link invoke the function.

Such as:

function Snowflakes() {
if (ns4up) {
snowNS();
} else if (ie4up) {
snowIE();
}
}

<a href="javascript:Snowflakes()">Snowflakes</a>

or

<img src="http://javascript.internet.com/img/snow/snow.gif"
border="0" width="24" height="24" onclick="Snowflakes()"
alt="Snowflakes" title="Snowflakes">


web.dev
Guest
 
Posts: n/a
#4: Sep 20 '05

re: How Do I Change to OnClick?



Jenny wrote:[color=blue]
> Hi - There's a neat little snowfall effect at
> http://javascript.internet.com/bgeffects/snow.html. I want to use it for a
> school project, but I need to run it by clicking on a button, rather than
> when the page loads. In the HTML, I want to use something like:
>
> <FORM>
> <INPUT TYPE="button" value="Winter Time" onClick="?????">
> </FORM>
>
> but I cannot figure out what to do with the actual script to make this work.
> I'd appreciate any suggestions. BTW, I'm a serious novice, so please keep it
> as simple as possible. Thank you.
> Jenny[/color]

Hi Jenny,

I'm going to assume you followed the exact instructions as that site
told you.
Secondly, towards the end of the code you should see the following
lines:

if (ns4up) {
snowNS();
} else if (ie4up) {
snowIE();
}

Replace those lines with the following:

function startSnow()
{
if(ns4up)
snowNS();
else if(ie4up)
snowIE();
}

Finally, in your HTML you can do what you wanted:

<input type = "button" value = "Winter Time" onClick = "startSnow()"/>

Hope this helps :)

Jenny
Guest
 
Posts: n/a
#5: Sep 20 '05

re: How Do I Change to OnClick?


"Jenny" <jwilliams64@earthlink.net> wrote in message
news:aRzXe.64253$SL.996468@twister.southeast.rr.co m...[color=blue]
> Hi - There's a neat little snowfall effect at
> http://javascript.internet.com/bgeffects/snow.html. I want to use it for a
> school project, but I need to run it by clicking on a button, rather than
> when the page loads. In the HTML, I want to use something like:
>
> <FORM>
> <INPUT TYPE="button" value="Winter Time" onClick="?????">
> </FORM>
>
> but I cannot figure out what to do with the actual script to make this
> work. I'd appreciate any suggestions. BTW, I'm a serious novice, so please
> keep it as simple as possible. Thank you.
> Jenny[/color]

Thanks to everyone for your help. It worked great! Thanks again, Jenny


Closed Thread