form question

They have: 2 posts

Joined: Aug 2002

Is there a way to have two different actions associated with one form? For example, I want to have it so that if the viewer selects an option for one drop-down menu, then the form does one thing, but if they choose any option for another drop-down menu, the form does something else.

They have: 447 posts

Joined: Oct 1999

you could do something like this:

<script LANGUAGE="javascript" TYPE="text/javascript">

function submitIt(theform) {
switch(theform.options[theform.options.selectedIndex].value) {
case 'red':
theform.action = 'redformhandler.php';
break;
case 'blue':
theform.action = 'blueformhandler.php';
break;
default:
theform.action = 'defaultformhandler.php';
}

theform.submit();
}

</script>

<FORM NAME="myform" ACTION="defaultformhandler.php" METHOD="post">

<P>
<SELECT NAME="options">
<OPTION VALUE=''>--select one--</OPTION>
<OPTION VALUE="red">Red</OPTION>
<OPTION VALUE="blue">Blue</OPTION>
</SELECT>

<P><INPUT TYPE="button" VALUE="Click Me!" ONCLICK="submitIt(document.myform)">
</FORM>
'

that *should* work, dont have time to test it out.

The Webmistress's picture

She has: 5,586 posts

Joined: Feb 2001

When you say the form does something, what exactly do you mean? Go to a URL or email or some other function??

They have: 2 posts

Joined: Aug 2002

One action is to go to another site that accesses a paging system (but the action set on the form right now does this through a URL), the other action (which needs to be added still) would send out an email.

He has: 1,016 posts

Joined: May 2002

Sounds to me like you need a backend script..

Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.