By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,569 Members | 1,181 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,569 IT Pros & Developers. It's quick & easy.

changing ONCLICK

P: n/a
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
Oct 2 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
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">

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Oct 2 '05 #2

P: n/a
> "Stefan Finzel" <St***************@T-Online.de> wrote:
news:dh*************@news.t-online.com....

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>

--
BootNic Sunday, October 02, 2005 8:43 PM

Thirty-five is when you finally get your head together and your body starts falling apart.
*Caryn Leschen*

Oct 3 '05 #3

P: n/a
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
Oct 5 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.