Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Dynamically change ACTION field

Status
Not open for further replies.

salewit

Programmer
Oct 31, 2002
58
US
I've got a form where the output of the form will go to 75 possible different places based on the user input. I can't figure out how to dynamically change the ACTION field based on the input. I've got:

<form name="formx" action="???" method="post">

<select name="year">
<option>Select Year<option>2003<option>2004<option>2005</select>

<select name='month'>
<option>Select Month<option>January<option>February<option>etc</select>
<select name='type'>
<option>Read Thread Online<option>Download Entire Thread</select>

<input type="submit" value="Go To Page">
</form>

The ACTION based on the input would be:

or html)

I've searched around, and have found several examples based on ONE select type, but I can't find or figure out multiples.
 
Code:
var theURL = "thhp://[URL unfurl="true"]www.domain.com/archives/"[/URL] + 
   document.formx.year(document.formx.year.selectedIndex).value + "/" + 
   document.formx.month(document.formx.month.selectedIndex).value + "." + 
   document.formx.type(document.formx.type.selectedIndex).value;
document.formx.action = theURL;
document.formx.submit();


Tracy Dryden

Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard. [dragon]
 
Code:
function getAction(f) {
    var y = f.elements['year'].options[f.elements['year'].selectedIndex].value;
    var m = f.elements['month'].options[f.elements['month'].selectedIndex].value;
    var t = f.elements['type'].options[f.elements['type'].selectedIndex].value;

    f.action = "[URL unfurl="true"]http://www.domain.com/archives/"[/URL] + y + "/" + m + "." + t;
}

and

Code:
<form name="formx" ... onsubmit="getAction(this);">

*cLFlaVA
----------------------------
[tt]tastes great, less filling.[/tt]
[URL unfurl="true"]http://www.coryarthus.com/[/url]
 
Wow, thank you guys SO much! Worked like a charm. If you knew how long I've been trying to do this on my own.... I'll have to start learning Javascript.

Sam
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top