Skip to main content
Inspiring
September 15, 2006
Question

change form action upon drop down selection

  • September 15, 2006
  • 1 reply
  • 320 views
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. Any ideas or code snippets appreciated.
This topic has been closed for replies.

1 reply

jsltdAuthor
Inspiring
September 15, 2006
since posting this 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>

Is there an alternative to changing the action of a form for this ?

I basically want to create a search facility on the site. From a text box, drop down and submit button I want the user to be able to select the area of the site they wish to search and target that area.

Two of the areas are database data, the other is going to be text search in html. I can handle the queries/search results, I just need to figure out how I can target the results page dependant on the users choice of search category (from the drop down)

I had planned to just pass the variable form the text input to the results page and the results page would do the rest from the recordset sql query. But if I can't target a specific page depending upon the users choice of category, how can I determine what results to display ?

Any advice appreciated.