473,397 Members | 2,077 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,397 software developers and data experts.

Two submit buttons, which one was pressed?

Dear all

I need to be able to check which one out of two submit buttons within
the same form was pressed in a javascript function prior to form
submission. And before I get flamed for not finding the answer in
previous posts - I have already seen this question answered numerous
times in this forum, only problem is that the recommended method is
not available to me :-(. I know that if I could code an onclick event
on the <input type=submit> tag, then call a function which sets a
value corresponding to the button clicked, this would be a cinch, but
I can't as I am working with a templated system which automatically
generates the <input> tags.

Question to you guys, is there any other way of getting this info in
my javascript function?
Code (shortened)
----------------

<SCRIPT LANGUAGE="JavaScript1.1">

function verify(f)
{

Need to put code in here to check which of the two submit buttons was
pressed, as makes no sense to user to validate input when they press
the 'cancel order' button.

}
</SCRIPT>

<FORM onSubmit="return verify(this);" ACTION="somescript.exe"
METHOD=POST>

<INPUT TYPE=text NAME=delName VALUE="">
<TEXTAREA ROWS=4 COLS=32 NAME=delAddr></TEXTAREA>
<INPUT TYPE=text NAME=delTown VALUE="">

<INPUT NAME="op-basket-cancel_order" TYPE=submit VALUE="Cancel Order">
<INPUT NAME="op-basket-confirm_order" TYPE=submit VALUE="Go To
Checkout">

</FORM>

Grateful for any advice, or if anyone can spot a different workround
to solve my problem.

Actionwoman63
Jul 23 '05 #1
4 4107
On 23 Nov 2004 10:41:06 -0800, actionwoman63 wrote:
...And before I get flamed for not finding the answer in
previous posts - I have already seen this question answered numerous
times in this forum, ...
Intriguing you should say that, given this form of the script element..
<SCRIPT LANGUAGE="JavaScript1.1">
...has been also commented upon, many times in the posts of this forum.
Need to put code in here to check which of the two submit buttons was
pressed, .. .... <INPUT NAME="op-basket-cancel_order" TYPE=submit VALUE="Cancel Order">


getElementByName() might help you identify the originating button
in this case.

HTH

--
Andrew Thompson
http://www.PhySci.org/codes/ Web & IT Help
http://www.PhySci.org/ Open-source software suite
http://www.1point1C.org/ Science & Technology
http://www.LensEscapes.com/ Images that escape the mundane
Jul 23 '05 #2
In article <1e**************************@posting.google.com >,
s.*****@justmail.me.uk says...
Dear all

I need to be able to check which one out of two submit buttons within
the same form was pressed in a javascript function prior to form
submission. And before I get flamed for not finding the answer in
previous posts - I have already seen this question answered numerous
times in this forum, only problem is that the recommended method is
not available to me :-(. I know that if I could code an onclick event
on the <input type=submit> tag, then call a function which sets a
value corresponding to the button clicked, this would be a cinch, but
I can't as I am working with a templated system which automatically
generates the <input> tags.

Question to you guys, is there any other way of getting this info in
my javascript function?
Code (shortened)
----------------

<SCRIPT LANGUAGE="JavaScript1.1">

function verify(f)
{

Need to put code in here to check which of the two submit buttons was
pressed, as makes no sense to user to validate input when they press
the 'cancel order' button.

}
</SCRIPT>

<FORM onSubmit="return verify(this);" ACTION="somescript.exe"
METHOD=POST>

<INPUT TYPE=text NAME=delName VALUE="">
<TEXTAREA ROWS=4 COLS=32 NAME=delAddr></TEXTAREA>
<INPUT TYPE=text NAME=delTown VALUE="">

<INPUT NAME="op-basket-cancel_order" TYPE=submit VALUE="Cancel Order">
<INPUT NAME="op-basket-confirm_order" TYPE=submit VALUE="Go To
Checkout">

</FORM>

Grateful for any advice, or if anyone can spot a different workround
to solve my problem.


Write code that listens to a specific event for a particular object:

<script for="op-basket-cancel_order" event="onclick"
type="text/javascript">
alert("You pressed op-basket-cancel_order");
</script>

<script for="op-basket-confirm_order" event="onclick"
type="text/javascript">
alert("You pressed op-basket-confirm_order");
</script>

<input type="button" name="op-basket-cancel_order" value="op-basket-
cancel_order">
<input type="button" name="op-basket-confirm_order" value="op-basket-
confirm_order">

--
Hywel
Jul 23 '05 #3
On Tue, 23 Nov 2004 19:08:22 -0000, Hywel Jenkins
<hy**********@hotmail.com> wrote:

[snip]
Write code that listens to a specific event for a particular object:

<script for="op-basket-cancel_order" event="onclick"
type="text/javascript">
alert("You pressed op-basket-cancel_order");
</script>

<script for="op-basket-confirm_order" event="onclick"
type="text/javascript">
alert("You pressed op-basket-confirm_order");
</script>


Eww. Non-standard use of the SCRIPT element.

You could use

document.forms['formName/Id'].elements[
'op-basket-cancel_order'
].onclick = function(evt) {
/* Code here. */
};

document.forms['formName/Id'].elements[
'op-basket-conform_order'
].onclick = function(evt) {
/* Code here. */
};

added either onload (which could be added programatically, too), or in a
SCRIPT element placed after the elements. After the FORM's closing tag
might be safest.

[snip]

Mike

--
Michael Winter
Replace ".invalid" with ".uk" to reply by e-mail.
Jul 23 '05 #4
actionwoman63 wrote on 23 nov 2004 in comp.lang.javascript:
<FORM onSubmit="return verify(this);" ACTION="somescript.exe"
METHOD=POST>

<INPUT TYPE=text NAME=delName VALUE="">
<TEXTAREA ROWS=4 COLS=32 NAME=delAddr></TEXTAREA>
<INPUT TYPE=text NAME=delTown VALUE="">

<INPUT NAME="op-basket-cancel_order" TYPE=submit VALUE="Cancel Order">
<INPUT NAME="op-basket-confirm_order" TYPE=submit VALUE="Go To
Checkout">

</FORM>


If you are not in for the other poster's
<script for="op-basket-cancel_order" coding,
try this:

=============================

<form onsubmit="alert(clicked);return clicked=='confirm'"
action="somescript.exe" method=post>

<input type=text name=delname value="">
<textarea rows=4 cols=32 name=deladdr></textarea>
<input type=text name=deltown value="">

<input name="op-basket-cancel_order" type=submit value="cancel order"
onclick="clicked='cancel'">
<input name="op-basket-confirm_order" type=submit
value="go to checkout"
onclick="clicked='confirm'">

</form>
--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress,
but let us keep the discussions in the newsgroup)

Jul 23 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Bill Puetz | last post by:
I have a form with 4 different Submit buttons. In the action code, I do a request on the button names to see which one is valued. This all works great, until the browser is refreshed -- the...
8
by: Syed Ali | last post by:
Hello, I have 1 HTML form with 4 submit buttons and 10 textfield entry areas. If submit button1 is pressed I need to make sure that all 10 textfield entries have been filled before submitting...
15
by: M Smith | last post by:
I have a form I want to submit to itself. I want to be able to type in a list of numbers and submit the form and have that list show up on the same form under the text box I typed them into and...
6
by: CJM | last post by:
Can somebody clarify if/how/when a simple form is submitted when the <Enter> key is pressed? As I understood it, if you have a form with a single submit button, if enter is pressed, the form...
3
by: M | last post by:
i am using submit buttons to send the user to different parts of a wizard. i am using if (if attribute.step1 exists) statements to send them to the appropriate section based on which submit button...
3
by: Arun K | last post by:
Hi, I am creating a simple .aspx page to add some fields with validation. I have used different .NET validations like REquiredFieldValidator, RegularExpressionValidator and showed the summary...
6
by: stellstarin | last post by:
I have a HTML page containing two submit buttons in the same form.When the form is submitted,I want to know through which submit button the form was submitted. Is there any event or property which...
2
by: Mike P | last post by:
Can you have 2 submit buttons in one <formelement? I have a form with a few dropdowns and textboxes that has a submit button to write the data to a database, but I also need a submit button next...
1
by: abcdriver | last post by:
Later edit: Too complex: The only thing I should know is: The submit button's NAME (and value) will only be sent if that particular button was used to submit the form, so you should be able to...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.