Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

one form, two (type=image) submit buttons 2

Status
Not open for further replies.

worldwise

Programmer
Jun 1, 2005
112
US
I have one form with two submit buttons of type image. I use ASP with vbscript.

I have done this before where I used regular submit buttons and simply used different name values. Then on the next page I would do "If request.form("submitButtonName") = "blah" Then 'do something

However, for some reason when I use submit buttons with type="image" then using the name or value attributes doesn't do anything.

How can I tell which button was pressed?
 
you might have to resort to using javascript to set a hidden field value. however, that would leave non-javascript users in the dust.

why not use a standard submit button, and use a background image, like this:

Code:
<input type="submit" value="" style="background-image: url([URL unfurl="true"]http://www.tek-tips.com/images/logo.gif);[/URL] width: 210px; height: 114px; border: 0;" />



*cLFlaVA
----------------------------
[tt]somebody set up us the bomb![bomb][/tt]

[URL unfurl="true"]http://www.coryarthus.com/[/url]
 
so I guess its safe to say that type="submit" and type="image" buttons work differently? I mean, when I use the type="submit" button, I can see which button was pressed simply by checking the request.form("buttonName"), but doesn't work for type="image" buttons.

If thats the case, I will go back to using regular submit type forms - unless someone has a great way for me to do the same thing with type="image" buttons.
 
allegedly, the only thing passed when an image input is clicked is the x and y coordinates of the image input, which, in my opinion, is worthless.



*cLFlaVA
----------------------------
[tt]somebody set up us the bomb![bomb][/tt]

[URL unfurl="true"]http://www.coryarthus.com/[/url]
 
worldwise said:
so I guess its safe to say that type="submit" and type="image" buttons work differently?[/worldwise]
That would be a very good assumption, especially since it should be clear to anyone that there would be no point in having two different input types that would behave the same. In order for one to understand input type="image", one needs to come up with an explanation why it is there anyway.

Image submits were included for the server-side image maps. Similar to a client side image map, where clicking in different areas takes you to different places by providing information on the wheretos and area sizes and positions in the area tag, you can use image submit for the same thing. Except that you do it server-side. Image submit sends coordinates in x (for horizontal) and y (for vertical), telling you where in the image you clicked and allowing you to process that on the server (if the user clicked between 0 <x<100 then perform this).

AFAIK image submits send the coordinates along with the submit name over to the next page. If you use get method in the form and you can see what is passed in the URL address bar -- it would usually look like this ?myButton.x=15&myButton.y=20.

I am not sure what that translates into ASP, I know that PHP interprets (because myButton.x would be an illegal way to write a variable) this into myButton_x. In this way you're right, the button name is no longer carried over to the next page as a true or false value -- the name along with coordinates is. I suggest you inspect the whole Request.QueryString or Request.Form in order to see how the image submit was carried over. Using that you will find out how to reference your button value and will be able to use almost similar code.

Hope that answers it.
 
Vragabond,

awesome post. thank you! I have figured it out.

Basically when a image button is clicked, the following information is sent over in POST: x coordinate and y coordinate.

These values can be referenced by: request.form("buttonName.x") and request.form("buttonName.y").

All you have to do is name your two image buttons differently, and the one that is clicked will have a numerical value and the one that wasn't will have an empty string - and that is how you can tell which was clicked.

Thanks!

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top