Web Hosting, Design, & Coding forum

General discussion

change form action upon drop down selection

I'm trying to find the best (browser supported) way of changing the action of a form based on the selection of a drop down box.

I've found a script that works in Firefox but not IE:

<SCRIPT LANGUAGE="JavaScript"><!--
function setAction() {
if (navigator.appName.indexOf('Netscape') > -1) {
document.formName.action = document.formName.selectName.options[document.formName.selectName.selectedIndex].value;
return true;
else {
alert('Sorry, your browser does not support the changing of the action property of a form');
return false;


Could this concept work in IE with different javascript ? Or is this the wrong way to go about it.

Any ideas or code snippets appreciated.

Discussion is locked
You are posting a reply to: change form action upon drop down selection
The posting of advertisements, profanity, or personal attacks is prohibited. Please refer to our CNET Forums policies for details. All submitted content is subject to our Terms of Use.
Track this discussion and email me when there are updates

If you're asking for technical help, please be sure to include all your system info, including operating system, model number, and any other specifics related to the problem. Also please exercise your best judgment when posting in the forums--revealing personal information such as your e-mail address, telephone number, and address is not recommended.

You are reporting the following post: change form action upon drop down selection
This post has been flagged and will be reviewed by our staff. Thank you for helping us maintain CNET's great community.
Sorry, there was a problem flagging this post. Please try again now or at a later time.
If you believe this post is offensive or violates the CNET Forums' Usage policies, you can report it below (this will not automatically remove the post). Once reported, our moderators will be notified and the post will be reviewed.
Collapse -
try this?

In reply to: change form action upon drop down selection

i haven't tried it out but take away the if part like so and try it.

<script language="javascript">
function setAction() {
document.formName.action = document.formName.selectName.options[document.formName.selectName.selectedIndex].value;

Collapse -
hey slim I did it and it works

In reply to: try this?

Doh, why did that script block IE ? Do you think its a security thing ? Is there a vulnerability there related to changing the form action using IE ?

Either way, it works and I wish I was awake enough to see it.

Thanks slim.

Collapse -
How old was what you found?

In reply to: hey slim I did it and it works

There are various browsers out there and sometimes things would work in one browser but not in another. So, some folks would note that to use their site you had to use a specific browser, e.g. this site is best viewed using IE is what some would say while others would favor Netscape as way back when these were your common browsers on Windows machines while others could use Mosaic or Lynx to surf the web.

The concern I'd have is whether or not your script would run on the client system if someone has things really locked down from a security perspective.


Collapse -
not sure how old, can't find now

In reply to: How old was what you found?

Good point, too much of a risk to base a search solution on javascript being enabled. I think I will look at using a server side solution to trapping the results.

Thanks for your thoughts.

Popular Forums

Computer Newbies 10,686 discussions
Computer Help 54,365 discussions
Laptops 21,181 discussions
Networking & Wireless 16,313 discussions
Phones 17,137 discussions
Security 31,287 discussions
TVs & Home Theaters 22,101 discussions
Windows 7 8,164 discussions
Windows 10 2,657 discussions


This one tip will help you sleep better tonight

A few seconds are all you need to get a better night's rest.