Determining which button was pressed.

I have a HTML page with two submit buttons ie. one to go back and one to go forward.  I need to determine which button was pressed, so that my CGI can perform the desired operation.
dl090597Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

julio011597Commented:
What about giving them a different NAME and parse the resulting QUERY_STRING to see which one the user clicked on?
0
hung120397Commented:
Use imagebuttons and give your buttons the same name but different values:

<INPUT TYPE=IMAGE NAME=submit_button VALUE=forward SRC="..">
<INPUT TYPE=IMAGE NAME=submit_button VALUE=backward SRC="..">

In your cgi, check for this values to determine which one is selected.

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
PozzoCommented:
I disagree with you.
You cant send a value with an input type=image, you can just send
the coordinate x,y of the cursor when the user click on the
image...
the solution from julio is good.

but u can also use normal submit button like this

<input type="submit" name="my_submit" value="go_back">
<input type="submit" name="my_submit" value="go_forward">

and in your cgi, you should test the value of the my_submit parameter...

if you absolutly want to use image i suggest that you use
just one large image with the 2 buttons and in your cgi you test
the x/y coordinate to know where the user has clicked

(sorry for my terrible english...)
0
dagmarCommented:
In the case of submit buttons, the text displayed on the button face is what is set by it's VALUE attribute.  Those buttons above would read "go_back" and "go_forward" to the user--better to use proper spacing and capitalization.  :)

To clarify and elaborate, if you are using something like cgi-bin.pl (version 2.14 recommended) with perl, this gets a LOT easier...  Just keep in mind that the input button that gets clicked on will return through the input hash as a NAME VALUE pair, where NAME is the key in the hash.  If you name one button "FORWARD" and the other one "BACK", and set the values to whatever you like then your code is just...

#!/usr/bin/perl

require "cgi-bin.pl"

if (&ReadParse(\%Input)) {
  if (exists $Input{'FORWARD'}) {
    &A_forward_we_will_go;
  }
  if (exists $Input{'BACK'}) {
    &We_must_go_back;
  }
} else {
  # Please try not to use massively long routine names in
  # actual practice.  Teehee!  This will let you use the
  # same CGI to both print the form and show the results
  &User_supplied_no_input_so_we_must_have_just_been_called;
}

...this can of course be shortened considerably with the use of elsif.  The method of calling ReadParse to set the input hash
was done this way for a reason...  If a malicious user is checking for a buffer overflow, and submits more than a certain amount of data, ReadParse will return false (in addition to writing to STDERR which will get picked up in the httpd error_log file), at which point there's really no point in bothering with trying to parse any of it anyway.  
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Scripting Languages

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.