Home Articles FAQs XREF Games Software Instant Books About Feedback Search Site-Map
irt.org logo

Q128 Is it possible to have a form perform a different action depending on what is selected in a drop down list?

irt.org | Knowledge Base | JavaScript | Form 7.2 | Q128 [ previous next ]

Q128 Is it possible to have a form perform a different action depending on what is selected in a drop down list?

In Netscape you can change the action attribute of a form with:

document.formName.action = 'whatever';

All you need to do is trap which option is selected:

document.formName.selectName.options[document.formName.selectName.selectedIndex].value;

The following brings it all together:

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

<FORM NAME="formName" ACTION="????????" METHOD="POST" onSubmit="return setAction()">

<SELECT NAME="selectName">
      <OPTION SELECTED VALUE="yes.html">Yes
      <OPTION VALUE="no.html">No
</SELECT>

<INPUT TYPE="SUBMIT">

</FORM>

Feedback on 'Q128 Is it possible to have a form perform a different action depending on what is selected in a drop down list?'


Provide feedback ...
AddThis Social Bookmark Button

Provide feedback ... AddThis Social Bookmark Button


Last Updated: 6th July 2009. Maintained by: Martin Webb and Michel Plungjan
irt.org liability, trademark, document use, privacy statement and software licensing rules apply.
Copyright © 1996-2009 irt.org, All Rights Reserved.