HighDots Forums  

change form action based on select option

Javascript JavaScript language (comp.lang.javascript)


Discuss change form action based on select option in the Javascript forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Arthur
 
Posts: n/a

Default change form action based on select option - 06-15-2007 , 12:02 PM








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.

Reply With Quote
  #2  
Old   
presci
 
Posts: n/a

Default Re: change form action based on select option - 06-15-2007 , 01:59 PM






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... (AT) nospam (DOT) com> wrote:
Quote:
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.



Reply With Quote
  #3  
Old   
Randy Webb
 
Posts: n/a

Default Re: change form action based on select option - 06-16-2007 , 05:31 PM



Georgi Naumov said the following on 6/16/2007 5:04 PM:
Quote:
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... (AT) nospam (DOT) com> wrote:
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>

Quote:
/**
* 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/


Reply With Quote
  #4  
Old   
Georgi Naumov
 
Posts: n/a

Default Re: change form action based on select option - 06-17-2007 , 03:07 AM




Randy Webb :
Quote:
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... (AT) nospam (DOT) com> wrote:
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;
Quote:
--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq/index.html
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/


Reply With Quote
  #5  
Old   
-Lost
 
Posts: n/a

Default Re: change form action based on select option - 06-17-2007 , 03:25 AM



Georgi Naumov wrote:
Quote:
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.


Reply With Quote
  #6  
Old   
Randy Webb
 
Posts: n/a

Default Re: change form action based on select option - 06-17-2007 , 12:15 PM



Georgi Naumov said the following on 6/17/2007 3:07 AM:
Quote:
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... (AT) nospam (DOT) com> wrote:
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.

Quote:
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/


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.