2 Submit Buttons Of Type Image: Which was used?

C

Colin Steadman

I have two buttons on my form and need to know which was
clicked. If I setup the buttons like this:

<input type="submit" value="submit" name="submit_to_array">
<input type="submit" value="submit" name="submit_to_db">

I can look in the Request.Form collection to see if
submit_to_array or submit_to_db appears to determine which
button was clicked. This works fine.

The problem is, I want to use an image instead of the
default button and I have changed the type from submit to
image, ie:

<input type="image" value="submit" name="submit_to_array"
src="images\add.gif">
<input type="submit" value="submit" name="submit_to_db"
src="images\submit.gif">

But when I do this I dont get either submit_to_array or
submit_to_db appearing in the Request.Form collection.
Where has this gone?

TIA,

Colin
 
R

Roland Hall

in message
: I have two buttons on my form and need to know which was
: clicked. If I setup the buttons like this:
:
: <input type="submit" value="submit" name="submit_to_array">
: <input type="submit" value="submit" name="submit_to_db">
:
: I can look in the Request.Form collection to see if
: submit_to_array or submit_to_db appears to determine which
: button was clicked. This works fine.
:
: The problem is, I want to use an image instead of the
: default button and I have changed the type from submit to
: image, ie:
:
: <input type="image" value="submit" name="submit_to_array"
: src="images\add.gif">
: <input type="submit" value="submit" name="submit_to_db"
: src="images\submit.gif">
:
: But when I do this I dont get either submit_to_array or
: submit_to_db appearing in the Request.Form collection.
: Where has this gone?

Hi Colin...

There is more than one way to accomplish this. This is one way...

Create a hidden element. If you want to use an image to submit, then add an
onclick event to an image. It doesn't have to be an input element. The
onclick event calls a script that sets the value you want to the hidden
element and then submits the form.

http://kiddanger.com/lab/form.html

Click either image to trigger the event.
Here is the code for the asp document.

<%@ Language=VBScript %>
<%
Option Explicit
Response.Buffer = True
dim submitTo
submitTo = Request.Form("submitTo")
Response.Write("You clicked: " & submitTo & vbCrLf)
%>

HTH...

--
Roland Hall
/* This information is distributed in the hope that it will be useful, but
without any warranty; without even the implied warranty of merchantability
or fitness for a particular purpose. */
Technet Script Center - http://www.microsoft.com/technet/scriptcenter/
WSH 5.6 Documentation - http://msdn.microsoft.com/downloads/list/webdev.asp
MSDN Library - http://msdn.microsoft.com/library/default.asp
 
D

Dan

All you need to do is check the x or y coordinate.

Simply:

If Request.Form("Image1Name.x") <> "" Then
...
ElseIf Request.Form("Image2Name.x") <> "" Then
...
End If
 

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

Forum statistics

Threads
473,796
Messages
2,569,645
Members
45,366
Latest member
GayT017679

Latest Threads

Top