473,396 Members | 1,929 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,396 software developers and data experts.

through which submit button the form was submitted

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 identifies this?

Apr 5 '06 #1
6 2128
you can asign different IDs to both the buttons and invoke appropriate
methods for each button's onsubmit event ....

Apr 5 '06 #2
VK

st*********@gmail.com wrote:
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 identifies this?


Unfortunately no - event model creators overlooked the variant of
multiple submit buttons in the form. onsubmit event contains FORM as
target/srcElement, so you cannot backtrace the pressed button.

Luckely click event is being processed before submit. So in your form:

<form action="foo.cgi" onsubmit="return validate(this)">
....
<input type="submit" name="act" value="Submit 1"
onclick="glbAct=this;">
<input type="submit" name="act" value="Submit 2"
onclick="glbAct=this;">
</form>

Now in validate() you can check global variable glbAct to find which
button was pressed.

Apr 5 '06 #3
as we are the middleware securing the backend application,we can't
able to change the html code in the backend application.
so we need to trace the details of the 'submit' button, when the form
submission was made .
(without adding anyother extra event handling ..like onclick())

Apr 5 '06 #4
st*********@gmail.com wrote:
as we are the middleware securing the backend application,we can't
able to change the html code in the backend application.
so we need to trace the details of the 'submit' button, when the form
submission was made .
(without adding anyother extra event handling ..like onclick())


In the HTML, give each submit button a different name and value.
Whichever one is clicked will send its name-value pair.

From the spec:

"If a form contains more than one submit button, only the
activated submit button is successful."

<URL:http://www.w3.org/TR/html401/interact/forms.html#submit-format>
You can add onclick attributes using script without modifying the HTML
at all (other than to add the script element of course), but don't make
your form submission script dependent.
--
Rob
Apr 5 '06 #5
If there are two submit buttons and your "method" attribute of your
form is "get" then the submitted buttons name and value appear as query
string parameters. Where as the one that is not submitted dont appear
in the query string.

This is possible when the button type is "submit".

Now if the button type is "image" then the workaround is different. I
was in a similar situation with some contraints. The constraints were -
no javascript to be used, no submit buttons but image buttons, and php
as the backend technology.

the HTML code was as below:
<Form method = post action="some.php">
<input type="image" name="n1[]" value="n1"/>
<input type="image" name="n2[]" value="n2"/>
</Form>

Now within "some.php" I can check which one of the image buttons was
clicked:

if($_REQUEST["n1"] == true){
//do something
} else if($_REQUEST["n2"] == true){
//do something else
}

In this case the names are treated as arrays. when the button is
clicked the array is populated.
$_REQUEST["n1"] == true checks that.

----------
Arvind

Apr 7 '06 #6
ar******@yahoo.com wrote:
Now if the button type is "image" then the workaround is different. I
was in a similar situation with some contraints. The constraints were -
no javascript to be used,
Nonsense. The two technologies are independent of one another.
[...]
<Form method = post action="some.php">
<input type="image" name="n1[]" value="n1"/>
<input type="image" name="n2[]" value="n2"/>
</Form>

Now within "some.php" I can check which one of the image buttons was
clicked:

if($_REQUEST["n1"] == true){
//do something
} else if($_REQUEST["n2"] == true){
//do something else
}


You were looking for

if (isset($_POST['n1']))

of course. And it is not necessary that the name ends with '[]'.
PointedEars
Apr 7 '06 #7

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

Similar topics

3
by: Nicolas Keller | last post by:
Hi! I'm used to have Mozilla for testing my PHP sites when I'm coding. The site's nearly finished, now I've made a test with the Internet Exlporer... guess what... failed. The problem: I'm...
15
by: Mattia | last post by:
Hi! I have a <form> that can be submitted thruogh three buttons and I need to tell witch one was pressed when the form was submitted. I now do it with 3 <input type="submit" name="..."...
3
by: John Dunlop | last post by:
(Note crosspost and follow-ups to ciwah.) Nicolas Keller wrote in thread "Differences in form handling btw Mozilla and IE?": > The problem: I'm using a form that submit's (POST) its data via...
2
by: ivanhoe | last post by:
All articles and tutorials I've seen on subject of forms say that if there's name and value for submit button(input tag with type="submit"), they'll get submitted along with the rest of the...
2
by: Margaret Werdermann | last post by:
Hi all: I'm having a nasty time with a particularly difficult piece of code and was hoping someone might be able to help me. I have a FormMail form that originally worked perfectly. Then, I...
8
by: bettina | last post by:
I want to submit a form but without a submit button. That's to say, I want that by giving a definite code in a field and then press <ENTER> the form will be submitted. For Example <form...
2
by: anonieko | last post by:
Scenario: You have a page that is TOO slow to refresh. But it allows partial flushing of html contents. I.e. Submit button already appears but you don't want your users to click on it prematurely...
3
by: Taras_96 | last post by:
Hi everyone, I've got a rather unconventional architecture that I'm having problems with... I have a form called "searchForm", that has an input of type "submit" (with name = "submitButton...
5
by: g | last post by:
Hi Guys.. i know this might sound really really simple, but I'm kinda stuck..I have this form..which has a table (created from stored procedure values)..once the table is populated..i have some...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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...

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.