For the uninitiated, the usual way that the contents of a form is submitted is when someone clicks on a button created with HTML (or XHTML) code like the following:
Alternatively, some people prefer to replace the default button with a graphical image. If the image is called, say, "buttonimage.gif", the code to do this might take the following form:
Search as you might, you will probably not be able to find any documentation in your HTML manual on how you can make a text link function as though a submit button has been clicked. And no wonder. HTML does not directly support such a feature.
Let's say you have a form that begins in the following way:
Now, suppose you want to have two text links, one of which is for "Paid Support" and the other for "Free Support". Clicking either of these text links is supposed to cause the form to be submitted, with some device to indicate which link was clicked.
Now add the following to your form prior to the closing FORM tag.
As you can see from the FORM snippet, when the text link "Paid Support" is clicked, getsupport will be called with the string "Paid". Likewise, when the text link "Free Support" is clicked, getsupport will be called with the string "Free" in its argument.
The function getsupport sets the form variable "supporttype", which you defined as a hidden field in the form, to the string given in its argument. This is "Free" or "Paid" depending on which link was clicked. It then submits to form to the CGI script you defined in the "action" attribute of the FORM tag.
There you have it. A text link that can be used to submit a form. Trivial, isn't it?
Do you find this article useful? You can learn of new articles and scripts that are published on thesitewizard.com by subscribing to the RSS feed. Simply point your RSS feed reader or a browser that supports RSS feeds at https://www.thesitewizard.com/thesitewizard.xml. You can read more about how to subscribe to RSS site feeds from my RSS FAQ.
This article is copyrighted. Please do not reproduce or distribute this article in whole or part, in any form.
It will appear on your page as: