changing ONCLICK

S

Stefan Finzel

Hi

what's the right way to add ONCLICK to a form button using javascript?

<HTML>...
<INPUT ID="RESET" NAME="RESET" TYPE="RESET" VALUE=" Reset ">No onclick
is used here


<SCRIPT TYPE="text/javascript">...
form.RESET.click = "javascript:reset_action();"
....
</SCRIPT>

TIA

Stefan
 
R

Randy Webb

Stefan Finzel said the following on 10/2/2005 2:20 PM:
Hi

what's the right way to add ONCLICK to a form button using javascript?

<HTML>...
<INPUT ID="RESET" NAME="RESET" TYPE="RESET" VALUE=" Reset ">No onclick
is used here

That is because reset buttons have a default action.
<SCRIPT TYPE="text/javascript">...
form.RESET.click = "javascript:reset_action();"
....
</SCRIPT>

Don't use a reset button if you don't want normal reset actions. Use a
plain button instead.

Give your form a name.
Access the button through the forms collection.
Give it an onclick (not click) action.

document.forms['formNAME'].elements['elementNAME'].onclick=reset_action;

<form name="formNAME">
<input type="button" value=" Reset " name="elementNAME">
 
B

BootNic

Stefan Finzel said:
what's the right way to add ONCLICK to a form button using
javascript?

<HTML>... <INPUT ID="RESET" NAME="RESET" TYPE="RESET" VALUE=" Reset
">No onclick is used here

<SCRIPT TYPE="text/javascript">... form.RESET.click =
"javascript:reset_action();" ... </SCRIPT>

If you want to run some javascript when the form is reset you may
want to consider using onreset=""

<form action="javascript:void();" id="myform" name="myform"
onreset="alert('well done grasshopper')">

Add onreset to form:

document.forms['myform'].onreset =
function r(){alert('well done grasshopper')};

OR add using Id

document.getElementById('myform').onreset =
function r(){alert('well done grasshopper')};

Add onclick:

document.forms['myform'].elements['reseta'].onclick =
function r(){alert('well done grasshopper')};

OR add using Id

document.getElementById('reseta').onclick =
function r(){alert('well done grasshopper')};

<form action="javascript:void();" id="myform" name="myform">
<input id="reseta" name="reseta" type="reset" value=" Reset ">
</form>
 
S

Stefan Finzel

As this should run on older Pocket IE (Win CE 2003 SE) is seems for me
only the click-Method is available.

But nethertheless using ONRESET immediatly is working and a better way
to get it right. So there is even no need to differ between browsers
here any more.

Thanks to all!

Stefan
 

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

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,599
Members
45,163
Latest member
Sasha15427
Top