Solved

Determining which button was pressed.

Posted on 1997-11-27
4
178 Views
Last Modified: 2013-12-25
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.
0
Comment
Question by:dl090597
4 Comments
 
LVL 5

Expert Comment

by:julio011597
Comment Utility
What about giving them a different NAME and parse the resulting QUERY_STRING to see which one the user clicked on?
0
 

Accepted Solution

by:
hung120397 earned 0 total points
Comment Utility
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
 

Expert Comment

by:Pozzo
Comment Utility
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
 
LVL 1

Expert Comment

by:dagmar
Comment Utility
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

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

In this tutorial I will show you how to make a simple HTML bar chart with the usage of WhizBase, If you want more information about WhizBase please read my previous articles at http://www.experts-exchange.com/ARTH_5123186.html (http://www.experts-ex…
I hope you'll find this tutorial useful and interesting. So let's try to extend Tcl with a new package.  For anyone more deeply interested please check out the book "Practical Programming in Tcl and Tk". It's really one of the best written books abo…
Learn the basics of if, else, and elif statements in Python 2.7. Use "if" statements to test a specified condition.: The structure of an if statement is as follows: (CODE) Use "else" statements to allow the execution of an alternative, if the …
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now