Web Hosting, Design, & Coding forum

General discussion

change form action upon drop down selection

by jsltd / September 16, 2006 8:10 PM PDT

Hi,
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;
}

}
//--></SCRIPT>

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?
by slim___shady / September 17, 2006 1:06 AM PDT

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;
}
<script>

Collapse -
hey slim I did it and it works
by jsltd / September 17, 2006 4:44 AM PDT
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?
by steve749 / September 17, 2006 7:57 AM PDT

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.

Regards,
JB

Collapse -
not sure how old, can't find now
by jsltd / September 17, 2006 5:15 PM PDT

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

GIVEAWAY

We are giving away 'Black Panther' swag!

Four lucky readers will be taking home *Marvel*ous "Black Panther" prizes, including magazines autographed by the King of Wakanda himself! Giveaway ends Feb. 25, 2018.