Solved

Determining which button was pressed.

Posted on 1997-11-27
4
192 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 5

Expert Comment

by:julio011597
ID: 1831474
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
ID: 1831475
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
ID: 1831476
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
ID: 1831477
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

Webinar: Aligning, Automating, Winning

Join Dan Russo, Senior Manager of Operations Intelligence, for an in-depth discussion on how Dealertrack, leading provider of integrated digital solutions for the automotive industry, transformed their DevOps processes to increase collaboration and move with greater velocity.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This tutorial will discuss fancy secure registration forms, with AJAX technology support. In this article I assume you already know HTML and some JS. I will write the code using WhizBase Server Pages, so you need to know some basics in WBSP (you mig…
Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
The viewer will learn how to count occurrences of each item in an array.
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

734 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