Two submit buttons, which one was pressed?

A

actionwoman63

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
 
H

Hywel Jenkins

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

Michael Winter

On Tue, 23 Nov 2004 19:08:22 -0000, Hywel Jenkins

[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
 
E

Evertjan.

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>
 

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,995
Messages
2,570,228
Members
46,818
Latest member
SapanaCarpetStudio

Latest Threads

Top