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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Change From Action Based Upon Selection

Status
Not open for further replies.

jsnull

IS-IT--Management
Feb 19, 2002
99
US
Attempting to figure out how to change a forms action, based upon a selection, once the 'submit' button is clicked. For example, if I select "one" the form would post to if I select two, the form would post to
Thanx!

Jim Null
info@ferncreek.com
 
A better solution may be to listen to the onchange event of the select node and change the form action then. The following code example might help show how you could do this:

Code:
<script type="text/javascript">
function updateAction(data, form) {
  var newAction = "[URL unfurl="true"]http://www."[/URL] + data + ".com/submit.php";
  form.action = newAction;
}
</script>
...
<form id="myForm" action="[URL unfurl="true"]http://www.example.com/submit.php">[/URL]
...
<select onchange="updateAction(this.value, this.form.id);">
  <option value="one">One</option>
  <option value="two">Two</option>
</select>
...
</form>
...

Let us know how you go.

Cheers,
Jeff

[tt]Visit my blog [!]@[/!] Visit Code Couch [!]@[/!] [/tt]

Make sure your web page and css validates properly against the doctype you have chosen - before you attempt to debug a problem!

FAQ216-6094
 
Thanx for your reply ... just wasn't able to get it to work. So I went to creating a 'confirmation' page with PHP and was able to handle it all with PHP redirects.

Much appreciated.

Jim Null
info@ferncreek.com
 
>onchange="updateAction(this.value, this.form.id);"
[tt]onchange="updateAction(this.value, this.form);"[/tt]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top