|
 |
asp_web_howto thread: 2 Submit Buttons On Form - How To Detect Which One Selected
Message #1 by "Rita Greenberg" <rg1@h...> on Fri, 30 Mar 2001 23:11:52
|
|
Hi.
I have 2 submit buttons on a form. One to add a record, one to delete a
record. When I get to the "action" called asp page, how can I determine
which submit button was clicked?
I would prefer not to use a hidden field, if possible.
Here's part of my code:
<form name="ModifyGroup" method="post" action="modifygroup1.asp">
<input type="submit" name="oAdd" value="AddUserToGroup">
<input type="submit" name="oDelete" value="RemoveUserFromGroup">
TIA.
Rita
Message #2 by "Sertial, Sam" <2495XX2@a...> on Fri, 30 Mar 2001 17:45:33 -0500
|
|
The second button should be type button:
<input type="submit" name="oAdd" value="AddUserToGroup">
<input type=Button name="oDelete" value="RemoveUserFromGroup">
then you call the function RemoveUserFromGroup()
-----Original Message-----
From: Rita Greenberg [mailto:rg1@h...]
Sent: Friday, March 30, 2001 6:12 PM
To: ASP Web HowTo
Subject: [asp_web_howto] 2 Submit Buttons On Form - How To Detect Which
One Selected
Hi.
I have 2 submit buttons on a form. One to add a record, one to delete a
record. When I get to the "action" called asp page, how can I determine
which submit button was clicked?
I would prefer not to use a hidden field, if possible.
Here's part of my code:
<form name="ModifyGroup" method="post" action="modifygroup1.asp">
<input type="submit" name="oAdd" value="AddUserToGroup">
<input type="submit" name="oDelete" value="RemoveUserFromGroup">
TIA.
Rita
Message #3 by "Peter Lanoie" <planoie@e...> on Fri, 30 Mar 2001 18:23:37 -0500
|
|
When you have multiple Submit buttons on one form, only the one you press
will be submitted with the form, thus you can simply test for the existance
of that button. You can chain these tests together into an If..ElseIf..End
If structure.
If Not IsEmpty(Request.Form("cmdButton1")) Then
'Button One was pushed
ElseIf Not IsEmpty(Request.Form("cmdButton2")) Then
'Button Two was pushed
End If
One thing I'd HIGHLY recommend while first learning about form and
querystring handling is to add this code into an include file, and put that
include file into any scripts you need to test request code. This will
display the contents of the whole querystring and the form. It can be very
handy to see exactly what the VBscript is seeing for input.
<%
Dim objItem
Response.Write "<b>QueryString Variables</b>:<br>" & vbcrlf
Response.Write "Count: " & Request.QueryString.Count & " Item(s)<br>" &
vbcrlf
Response.Write "<table border=""1"" cellpadding=""2"" cellspacing=""1"">" &
vbcrlf
For Each objItem In Request.QueryString
Response.Write "<tr><td align=""right"">" & objItem & "</td>"
Response.Write "<td>" & Request.QueryString(objItem) & "</td></tr>" &
vbcrlf
Next
Response.Write "</table>" & vbcrlf
Response.Write "<hr>" & vbcrlf
Response.Write "<b>Form Variables</b>:<br>" & vbcrlf
Response.Write "Count: " & Request.Form.Count & " Item(s)<br>" & vbcrlf
Response.Write "<table border=""1"" cellpadding=""2"" cellspacing=""1"">" &
vbcrlf
For Each objItem In Request.Form
Response.Write "<tr><td align=""right"">" & objItem & "</td>"
Response.Write "<td>" & Request.QueryString(objItem) & "</td></tr>" &
vbcrlf
Next
Response.Write "</table>" & vbcrlf
Response.Write "<hr>" & vbcrlf
%>
HTH,
Peter
-----Original Message-----
From: Rita Greenberg [mailto:rg1@h...]
Sent: Friday, March 30, 2001 6:12 PM
To: ASP Web HowTo
Subject: [asp_web_howto] 2 Submit Buttons On Form - How To Detect Which
One Selected
Hi.
I have 2 submit buttons on a form. One to add a record, one to delete a
record. When I get to the "action" called asp page, how can I determine
which submit button was clicked?
I would prefer not to use a hidden field, if possible.
Here's part of my code:
<form name="ModifyGroup" method="post" action="modifygroup1.asp">
<input type="submit" name="oAdd" value="AddUserToGroup">
<input type="submit" name="oDelete" value="RemoveUserFromGroup">
TIA.
Rita
Message #4 by "Adeola" <aoadeyemo@h...> on Sat, 31 Mar 2001 00:26:56
|
|
Hi Rita
Try this
<head>
<title>modifygroup.asp</title>
<script language = javascript>
function go(act)
{
modifygroup.txthide.value= act;
modifygroup.submit;
}
</script>
</head>
<body>
<% dim strtype
strtype = request.form("txthide")
if strtype = "Add" then
'code to add
else
'code to delete
end if
%>
<form name="ModifyGroup" method="post" action="modifygroup1.asp">
>
<input type="button" name="oAdd"
value="AddUserToGroup" onclick = "go(add);">
<input type="button" name="oDelete"
value="RemoveUserFromGroup" onclick = "go(delete);">
<input type= hidden name=txthide value="">
</form>
</body>
That piece of code will see u thru' 'n' probs just reply. Remember, i used
vbscript on the server side and javascript on the client + the page is
submitting to itself.
Good luck
Ade'
> Hi.
>
> I have 2 submit buttons on a form. One to add a record, one to delete a
> record. When I get to the "action" called asp page, how can I determine
> which submit button was clicked?
>
> I would prefer not to use a hidden field, if possible.
>
> Here's part of my code:
> <form name="ModifyGroup" method="post" action="modifygroup1.asp">
>
> <input type="submit" name="oAdd" value="AddUserToGroup">
> <input type="submit" name="oDelete" value="RemoveUserFromGroup">
>
> TIA.
>
Message #5 by "Wanschek, John J" <jjwansch@i...> on Fri, 30 Mar 2001 17:59:01 -0600
|
|
A Button is just another means of input.
In your action program put
Var = Request.form("name")
Var now Contains your answer.
JJW
-----Original Message-----
From: Rita Greenberg [mailto:rg1@h...]
Sent: Friday, March 30, 2001 5:12 PM
To: ASP Web HowTo
Subject: [asp_web_howto] 2 Submit Buttons On Form - How To Detect Which
One Selected
Hi.
I have 2 submit buttons on a form. One to add a record, one to delete a
record. When I get to the "action" called asp page, how can I determine
which submit button was clicked?
I would prefer not to use a hidden field, if possible.
Here's part of my code:
<form name="ModifyGroup" method="post" action="modifygroup1.asp">
<input type="submit" name="oAdd" value="AddUserToGroup">
<input type="submit" name="oDelete" value="RemoveUserFromGroup">
TIA.
Rita
|
|
 |