Using an Image to Submit Data

You may use an imagecalled an active imageas a combination input element and submit button. In addition to submitting the data from the other fields in the form, a click on the image sends the current mouse coordinates to the server in two name-value pairs.

To use an image to submit data:


Create a GIF or JPEG image.


Type <input type="image".


Type src="/books/2/62/1/html/2/image.url", where image.url is the location of the image on the server.


Type name="label", where label will be appended by x and y and will identify the x and y coordinates sent to the server, when the visitor clicks the image.


Type alt="description", where description will appear if the image does not.


Type the final /> to finish the active image definition for the form.

Figure 17.51. If you use an active image, you don't need a submit button.

Figure 17.52. The same form can have both regular fields (like the radio buttons) and an image map. When the visitor clicks the map, all of the data is sent to the script.

Figure 17.53. This script outputs the coordinates from the mouse click in the image along with the radio button value.


  • Setting the value attribute has no effect. The values are set to the mouse coordinates automatically.

  • In a Perl script, the names are set to label.x and label.y for the x and y coordinates respectively, where label matches what you used in step 4 above, x is the horizontal distance in pixels from the image's left edge, and y is the vertical distance in pixels from the image's top edge. In a PHP script, the names are changed to label_x and label_y instead since PHP doesn't accept periods in variable names.

  • You can find the PHP script used in this example on my Web site (see page 26).

HTML, XHTML, & CSS(c) Visual QuickStart Guide
HTML, XHTML, and CSS, Sixth Edition
ISBN: 0321430840
EAN: 2147483647
Year: 2004
Pages: 340

Similar book on Amazon © 2008-2017.
If you may any questions please contact us: