Log In    |    Knowledge Base    |    4D Home
Tech Tip: Finding out which picture was clicked to submit an HTML form
Published On: July 27, 2001
Your current browser may not allow you to download the asset. We recommend Mozilla Firefox or Google Chrome.
Log In

When an HTML form is submitted by clicking on one of several image type inputs, you will need a way to determine which picture was selected.

First of all, you should know that for a picture to submit a form when it is clicked, it needs to have an HTML definition similar to the following (optional attributes have been removed):

<input type="image" name="imageField1" src="4D.GIF">

If 4D.GIF was the picture clicked, when the form action method executes you will get two process variables: imagefield1_x and imagefield1_y. These two variables house the x-axis and y-axis coordinates of the click within the frame of the picture for imagefield1. These two variables, when they are set, are always positive but can be zero. If the user were to click a different picture, you would then obtain similar variables respective to the other picture's name. In that case, the variables imagefield1_x and imagefield1_y would not be passed to 4D at all.

As you may already know, incoming Web variables should be declared in a Compiler_Web method. If you use the following code in the Compiler_Web method it will both declare the imagefield1_x variable AND initialize it to a negative value.

C_TEXT (imagefield1_x)

Why initialize it to a negative value? It is simple: in the process that is created by the form action, if the variable remains negative, it means that the corresponding picture was not clicked. If the value is greater than or equal to 0, it means the picture was clicked. You can then branch your code based on that test.