Wrox Programmer Forums
|
ASP Forms As of Oct 5, 2005, this forum is now locked. Please use "Classic ASP beginner" at http://p2p.wrox.com/forum.asp?FORUM_ID=54 or "Classic ASP Professional" http://p2p.wrox.com/forum.asp?FORUM_ID=56 instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP Forms section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old December 21st, 2004, 11:32 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 428
Thanks: 57
Thanked 2 Times in 2 Posts
Default 2 Submit Buttons - Which one was clicked?

I have an ASP generated page that I wish to contain TWO submit buttons. The form_OnSubmit function is called automatically to validate data on the client side before the next page is called.

I would like to know which of the two submit buttons called the form_OnSubmit function because I wish to vary the QueryString accordingly. How can I tell which submit button called form_OnSubmit?
 
Old December 21st, 2004, 04:07 PM
Authorized User
 
Join Date: Jun 2004
Posts: 34
Thanks: 0
Thanked 0 Times in 0 Posts
Default

after the page is submitted check the name of the submit button. provided that the names of the buttons are unique. and then use the if , else statement.


 
Old December 21st, 2004, 04:54 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 428
Thanks: 57
Thanked 2 Times in 2 Posts
Default

Yes, but how do I check the name of the button? Could you provide a code example in vbscript?
 
Old January 7th, 2005, 04:34 AM
Registered User
 
Join Date: May 2004
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default

try http://www.chami.com/tips/internet/042399I.html

 
Old January 7th, 2005, 05:21 AM
Friend of Wrox
 
Join Date: Dec 2004
Posts: 307
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to Vadivel Send a message via Yahoo to Vadivel
Default

Why not have a OnClick function on each button?

Best Regards
Vadivel

MVP ASP/ASP.NET
http://vadivel.thinkingms.com
 
Old January 7th, 2005, 02:03 PM
Friend of Wrox
 
Join Date: Nov 2004
Posts: 1,621
Thanks: 1
Thanked 3 Times in 3 Posts
Default

In the Request.Form, any element that does not exist reads like an empty string.
If you have two submit buttons with the same name, but a different face (value = ...), then that element will be equal to the face of the button clicked.

With
Code:
<form . . .>
    <submit name="btnSubmit" value="Save">&nbsp;
    <submit name="btnSubmit" value="Cancel">
</form>
at the server, if the save button is clicked, Request.Form("btnSubmit") will be equal to "Save". If there is no such element as "ab123", then Request.Form("ab123") will be equal to "".

If, on the other hand, you have
Code:
<form . . .>
    <submit name="btnSave"   value="Save">&nbsp;
    <submit name="btnCancel" value="Cancel">
</form>
and you click the save button, Request.Form("btnSave") will be "Save" and Request.Form("btnCancel") will be "".
 
Old January 14th, 2005, 05:34 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 428
Thanks: 57
Thanked 2 Times in 2 Posts
Default

Ah - this is exactly what I was looking for. I'd never have thought of putting a value on the button and then requesting the button's value. Thank you Brian!

And thank you Snowbelly for the link. The code there appears to be somewhat similar.

And I assume that was what Iniro was also trying to tell me.

Quote:
quote:Originally posted by BrianWren
 In the Request.Form, any element that does not exist reads like an empty string.
If you have two submit buttons with the same name, but a different face (value = ...), then that element will be equal to the face of the button clicked.

With
Code:
<form . . .>
    <submit name="btnSubmit" value="Save">&nbsp;
    <submit name="btnSubmit" value="Cancel">
</form>
at the server, if the save button is clicked, Request.Form("btnSubmit") will be equal to "Save". If there is no such element as "ab123", then Request.Form("ab123") will be equal to "".

If, on the other hand, you have
Code:
<form . . .>
    <submit name="btnSave"   value="Save">&nbsp;
    <submit name="btnCancel" value="Cancel">
</form>
and you click the save button, Request.Form("btnSave") will be "Save" and Request.Form("btnCancel") will be "".





Similar Threads
Thread Thread Starter Forum Replies Last Post
How 2 Send Email When Submit Clicked BrianWren ASP.NET 1.0 and 1.1 Professional 4 April 21st, 2006 11:55 AM
2 Submit Buttons ... HOW? Benno Dreamweaver (all versions) 1 November 23rd, 2004 12:14 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.