473,466 Members | 1,508 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

change form action based on select option



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
6 19130
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
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
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

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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: M | last post by:
i have a form which i would like to input different "action" url depending on the button that was clicked. is there a way that javascript can prefill a defined action based on the button...
6
by: Bonge Boo! | last post by:
This has got to be obvious, but I can't make it work. I have a form called with 3 pull down menus. They are linked to a database which generates the values for the <SELECT? Pull-downs. Lets...
14
by: xxbmichae1 | last post by:
I have a <select> object that i've set up an onchange event that fires in IE fine when I use the cursor up and down in the list, but If I use the cursor up and down in Firefox the event doesn't...
2
by: TJS | last post by:
in a custom control which renders a form, is there a way to define the form action other than the preset postback. I've seen several but they are all an httpModule of sorts. I would like to do...
0
by: sb | last post by:
i made a base page that inherit from System.Web.UI.Page i want to modify the htmle from action, how do i do i? here what i want to modify at runtime: <form name="_ctl1" method="post"...
3
by: ANTISPAM_garycnew_ANTISPAM | last post by:
What is the simplest way to retain the last option value selected in an html select object using javascript? I am currently using a server-side cgi language to accomplish this task, but it adds...
4
by: ANTISPAM_garycnew_ANTISPAM | last post by:
I am trying to figure out the best way to change a form's action based on a single text input event. I have a search form within a larger form and would like to allow users to use the enter key...
3
by: phpnewbie2007 | last post by:
Hello, I have a dropdown which populates from a database. When user selects option 1 from the dropdown, he should be directed to sample.php, if he selects option 2, then to sampleb.php and so on....
20
idsanjeev
by: idsanjeev | last post by:
hello i want to modify multiple rows in database with select option i am using R.update but it can update only one record in database but i wants to more then one record is modify after submit so...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.