Changing Form Action URLs On-The-Fly
By Will Bontrager
2003-09-03
Reader Rating:

Mention #2, 3 & 4
Mention #2
The radio buttons that are the key for the JavaScript to determine the action="_____" URL don't necessarily need to have a value attribute. If your CGI scripts require values, you of course provide them, but they're not required for the JavaScript presented today.
Examples:
<input type="radio" name="reason">I have a Hot Tip!<br>
<input type="radio" name="reason">I saw a Cool Site!<br>
<input type="radio" name="reason">Get me outta here!<br>
Mention #3
The JavaScript can be anywhere on your page, in the HEAD area, in the BODY area above the form, or anywhere else that makes sense to you.
Mention #4
When JavaScript is used to consult a radio button to see whether or not it is checked, the first radio button in the set is button 0, the second button 1, and so forth.
To consult a radio button, both the form name and the name of the radio button's set are required. This JavaScript example consults the first radio button of the set to see if it's true that the button is checked:
if(document.myform.reason[0].checked == true)
Then if the button is checked, it proceeds to change the form's action="_____" URL to '/cgi-bin/mf1.cgi' -- like this:
if(document.myform.reason[0].checked == true) {
document.myform.action = '/cgi-bin/mf1.cgi';
}
Copyright 2004 Bontrager Connection, LLC
If you found this article interesting, you may want to read these as well:
|