How Do I Change to OnClick?

J

Jenny

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
 
A

ASM

Jenny said:
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:

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();"
 
M

McKirahan

Jenny said:
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

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">
 
W

web.dev

Jenny said:
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

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 :)
 
J

Jenny

Jenny said:
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

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

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,050
Latest member
AngelS122

Latest Threads

Top