Helping ordinary people create extraordinary websites!
HOME TUTORIALS SCRIPTS WEB HOSTING BLOG FORUM
Get Our Newsletter
Email:

Changing Form Action URLs On-The-Fly

By Will Bontrager
2003-09-03


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';
}


Tutorial Pages:
» Introduction
» Mention #1
» Mention #2, 3 & 4
» Method #5
» Mention #6
» The Complete Example


Copyright 2004 Bontrager Connection, LLC


 | Bookmark
Related Tutorials:
» JavaScript Debugging Techniques with Firebug
» Striped Tables Using JavaScript
» Opening PDFs in a New Window with JavaScript
» Essential Javascript -- A Javascript Tutorial
» Submit Forms Conditionally using JavaScript
» How to Setup a Randomising Function

Ask A Question
characters left.