change form action based on select option

A

Arthur

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.
 
P

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;
 
G

Georgi Naumov

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;


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>
 
R

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;


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.
 
G

Georgi Naumov

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;


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;
 
L

-Lost

Georgi said:
Randy Webb :
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?
 
R

Randy Webb

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;


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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,012
Latest member
RoxanneDzm

Latest Threads

Top