By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,451 Members | 981 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,451 IT Pros & Developers. It's quick & easy.

change form action based on select option

P: n/a


Hello.

How might it be possible to change where a form action is directed based on
a selected option.

For example I have this:

<FORM METHOD = "post" ACTION = "">

And a drop down such as

<Select name="formaction">
<option value="method1">method1</option>
<option value="method2">method2</option>
</select>

If option 1 is selected I need this to happen

<FORM METHOD = "post" ACTION = "http://www.thisdomain.com">
If option 2 is selected I need this to happen

<FORM METHOD = "post" ACTION = "http://www.thatdomain.com">

Thanks.
Jun 15 '07 #1
Share this Question
Share on Google+
6 Replies


P: n/a
write a event onchange and check for the selected index and
document.forms[0].action='blah';
or
document.forms[0].action=document.forms[0].selectbox.options[selectbox.selectedIndex].value;
On Jun 15, 9:02 am, Arthur <Art...@nospam.comwrote:
Hello.

How might it be possible to change where a form action is directed based on
a selected option.

For example I have this:

<FORM METHOD = "post" ACTION = "">

And a drop down such as

<Select name="formaction">
<option value="method1">method1</option>
<option value="method2">method2</option>
</select>

If option 1 is selected I need this to happen

<FORM METHOD = "post" ACTION = "http://www.thisdomain.com">

If option 2 is selected I need this to happen

<FORM METHOD = "post" ACTION = "http://www.thatdomain.com">

Thanks.

Jun 15 '07 #2

P: n/a
presci :
write a event onchange and check for the selected index and
document.forms[0].action='blah';
or
document.forms[0].action=document.forms[0].selectbox.options[selectbox.selectedIndex].value;
On Jun 15, 9:02 am, Arthur <Art...@nospam.comwrote:
Hello.

How might it be possible to change where a form action is directed based on
a selected option.

For example I have this:

<FORM METHOD = "post" ACTION = "">

And a drop down such as

<Select name="formaction">
<option value="method1">method1</option>
<option value="method2">method2</option>
</select>

If option 1 is selected I need this to happen

<FORM METHOD = "post" ACTION = "http://www.thisdomain.com">

If option 2 is selected I need this to happen

<FORM METHOD = "post" ACTION = "http://www.thatdomain.com">

Thanks.
.................................................. .................................................. ........................
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://
www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html;charset=utf-8"/>
<title>
</title>
<script type="text/javascript">
/**
* I thing that this
* way is much elegant
* than document.forms[0].action
* =document.forms[0].
* selectbox.options[selectbox.selectedIndex].value;
* @author Georgi Naumov
*/
function changeAction(aForm,aValue)
{
if(aValue=="")
return;
aForm.setAttribute("action",aValue);
}
</script>
</head>
<body>
<div>
<form action="somewhere.php" action="blanc.php">
<select name="myselect"
onchange="changeAction(this.form,this.value);">
<option value="">plese select action</option>
<option value="one.php">one</option>
<option value="three.php">three</option>
</select>
</form>
</div>
</body>
</html>

Jun 16 '07 #3

P: n/a
Georgi Naumov said the following on 6/16/2007 5:04 PM:
presci :
>write a event onchange and check for the selected index and
document.forms[0].action='blah';
or
document.forms[0].action=document.forms[0].selectbox.options[selectbox.selectedIndex].value;
On Jun 15, 9:02 am, Arthur <Art...@nospam.comwrote:
>>Hello.

How might it be possible to change where a form action is directed based on
a selected option.

For example I have this:

<FORM METHOD = "post" ACTION = "">

And a drop down such as

<Select name="formaction">
<option value="method1">method1</option>
<option value="method2">method2</option>
</select>

If option 1 is selected I need this to happen

<FORM METHOD = "post" ACTION = "http://www.thisdomain.com">

If option 2 is selected I need this to happen

<FORM METHOD = "post" ACTION = "http://www.thatdomain.com">

Thanks.
<snipped lots of XHTML that it takes a person of a particular mental
capacity to serve on the web>
/**
* I thing that this
* way is much elegant
* than document.forms[0].action
* =document.forms[0].
* selectbox.options[selectbox.selectedIndex].value;
* @author Georgi Naumov
You think wrong.

--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq/index.html
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Jun 16 '07 #4

P: n/a

Randy Webb :
Georgi Naumov said the following on 6/16/2007 5:04 PM:
presci :
write a event onchange and check for the selected index and
document.forms[0].action='blah';
or
document.forms[0].action=document.forms[0].selectbox.options[selectbox.selectedIndex].value;
On Jun 15, 9:02 am, Arthur <Art...@nospam.comwrote:
Hello.

How might it be possible to change where a form action is directed based on
a selected option.

For example I have this:

<FORM METHOD = "post" ACTION = "">

And a drop down such as

<Select name="formaction">
<option value="method1">method1</option>
<option value="method2">method2</option>
</select>

If option 1 is selected I need this to happen

<FORM METHOD = "post" ACTION = "http://www.thisdomain.com">

If option 2 is selected I need this to happen

<FORM METHOD = "post" ACTION = "http://www.thatdomain.com">

Thanks.

<snipped lots of XHTML that it takes a person of a particular mental
capacity to serve on the web>
/**
* I thing that this
* way is much elegant
* than document.forms[0].action
* =document.forms[0].
* selectbox.options[selectbox.selectedIndex].value;
* @author Georgi Naumov

You think wrong.
.................................................. ...................................
Why ? This:
aForm.setAttribute("action",aValue);
is shorter than:
document.forms[0].selectbox.options[selectbox.selectedIndex].value;
>
--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq/index.html
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Jun 17 '07 #5

P: n/a
Georgi Naumov wrote:
Randy Webb :
>You think wrong.
Why ? This:
aForm.setAttribute("action",aValue);
is shorter than:
document.forms[0].selectbox.options[selectbox.selectedIndex].value;
You are kidding me right? I'll ask you a question... which one of those
methods is cross-browser?

Or how about, which one of those methods will fail in a certain
mainstream browser?

--
-Lost
Remove the extra words to reply by e-mail. Don't e-mail me. I am
kidding. No I am not.
Jun 17 '07 #6

P: n/a
Georgi Naumov said the following on 6/17/2007 3:07 AM:
Randy Webb :
>Georgi Naumov said the following on 6/16/2007 5:04 PM:
>>presci :
write a event onchange and check for the selected index and
document.forms[0].action='blah';
or
document.forms[0].action=document.forms[0].selectbox.options[selectbox.selectedIndex].value;
On Jun 15, 9:02 am, Arthur <Art...@nospam.comwrote:
Hello.
>
How might it be possible to change where a form action is directed based on
a selected option.
>
For example I have this:
>
<FORM METHOD = "post" ACTION = "">
>
And a drop down such as
>
<Select name="formaction">
<option value="method1">method1</option>
<option value="method2">method2</option>
</select>
>
If option 1 is selected I need this to happen
>
<FORM METHOD = "post" ACTION = "http://www.thisdomain.com">
>
If option 2 is selected I need this to happen
>
<FORM METHOD = "post" ACTION = "http://www.thatdomain.com">
>
Thanks.
<snipped lots of XHTML that it takes a person of a particular mental
capacity to serve on the web>
>> /**
* I thing that this
* way is much elegant
* than document.forms[0].action
* =document.forms[0].
* selectbox.options[selectbox.selectedIndex].value;
* @author Georgi Naumov
You think wrong.
.................................................. ..................................
Why ?
setAttribute is known to be as buggy as a termite infested house in a
particular browser produced by a company in Redmond Washington, USA.
This:
aForm.setAttribute("action",aValue);
is shorter than:
document.forms[0].selectbox.options[selectbox.selectedIndex].value;
Shorter code isn't always better code.

onchange="this.form.action=this.value"

How much shorter, simpler, of a solution do you want for this question?
And I won't even get into the aspects of trying to write XHTML for the web.

--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq/index.html
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Jun 17 '07 #7

This discussion thread is closed

Replies have been disabled for this discussion.