Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > through which submit button the form was submitted

Reply
Thread Tools

through which submit button the form was submitted

 
 
stellstarin@gmail.com
Guest
Posts: n/a
 
      04-05-2006
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?

 
Reply With Quote
 
 
 
 
Madni
Guest
Posts: n/a
 
      04-05-2006
you can asign different IDs to both the buttons and invoke appropriate
methods for each button's onsubmit event ....

 
Reply With Quote
 
 
 
 
VK
Guest
Posts: n/a
 
      04-05-2006

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.

 
Reply With Quote
 
stellstarin@gmail.com
Guest
Posts: n/a
 
      04-05-2006
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())

 
Reply With Quote
 
RobG
Guest
Posts: n/a
 
      04-05-2006
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
 
Reply With Quote
 
arvindsd@yahoo.com
Guest
Posts: n/a
 
      04-07-2006
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

 
Reply With Quote
 
Thomas 'PointedEars' Lahn
Guest
Posts: n/a
 
      04-07-2006
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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Convert form to submit on load instead of clicking submit button? Network-Man HTML 5 07-07-2012 12:06 PM
Form submit: select not submitted Karsten Wutzke Javascript 3 12-05-2006 05:52 PM
submit the form data to the popup window without a submit button jrefactors@hotmail.com Javascript 2 01-01-2005 06:07 AM
submit the form data to the popup window without a submit button jrefactors@hotmail.com HTML 2 01-01-2005 06:07 AM
Form submit - hitting enter does not trigger Submit button ASP General 2 10-25-2004 03:37 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57