473,382 Members | 1,720 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

changing ONCLICK

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
3 2792
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
> "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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: martin | last post by:
I needed a way to display calculated, multiple, changing values (numerical sums) as users interacted with the page, and do this without going back to the server to load the page again. What I...
14
by: Brandon Hoppe | last post by:
I'm trying to change the src of an ilayer in the parent document from a link inside the ilayer. I'm not able to get it to work. All that happens is Netscape 4 crashes. This is for Netscape 4 only....
2
by: Ian F | last post by:
I have some javascript which allows a header, iframe and picture to be changed when the user clicks a next/previous button. In Opera, if you click next enough times to loop back to the start, or...
4
by: Gequina | last post by:
Something goes wrong in my script. I'm all new to it so i don't know much yet. I have a set of buttons. And when you click on either of them, the background image will change. Only it's not...
1
by: MickG | last post by:
I am trying to change the value of the variable "hard" according to which radio button is pressed and I am having no joy. Could anyone help me with this, the problematic section is marked with...
23
by: Wade | last post by:
08122005 1505 GMT-5 Hello. I am working on a webpage for the local school (just before school starts). Their outside hired company really screwed things up. Im trying to get their computers up...
5
by: Good Man | last post by:
Hi there I'm adding form fields on the fly with some javascript DOM programming. I basically just clone a hidden <div>, then adjust node properties to make this new <div> have unique values...
7
by: Stefan Finzel | last post by:
Hi, is there a way to change the display property on Windows Mobile 2003 SE Mobile/Pocket Internet Explorer? See following example. Please note: visibilty property has the same problem. Is...
13
by: amykimber | last post by:
Hi all, I know I'm doign something really daft, but I can't get this to work... I have a form with a bunch of inputs called ship_owner - why the ? Because I'm submitting this page though php...
7
by: Milenec | last post by:
Hi, so I was making this photo-gallery, and was using some javascript to make it look a little better, as in not having to refresh the entire page when you click on a thumbnail. I've gotten quite...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.