...

View Full Version : Multiple actions for single drop down menu



fyogi1
05-17-2005, 07:49 PM
I want to build a single drop down menu that will execute a different action dependent on the option selected.

Here is what I have. We have numerical indicators for pieces of equipment. I have three types of equipment. I currently have three separate drop down menus. I have it set that way because the action in the form is pointed to a certain file. Here is my current code:

<form method="POST" action="file1.php">
<SELECT name="site" onChange="form.submit()">
<option></option>
--------------------------------
<form method="POST" action="file2.php">
<SELECT name="site" onChange="form.submit()">
<option></option>
--------------------
<form method="POST" action="file3.php">
<SELECT name="site" onChange="form.submit()">
<option></option>
I want to combine these three into one drop down menu because the options are all numbers. But only certain numbers can go to certain php file because I have three different tables in my database. Also the three different php files display different information.

Here is another way to explain it:
options 1-5 goes to action="file1.php"
options 6-10 and 20 goes to action="file2.php"
options 11, 15, and 34 goes to action="file3.php"
All in one single drop down menu.

I am not sure this is even possible. Also I don't know javascript.
Thanks in advance.

webman33
05-30-2005, 03:15 PM
try this:

<form name="form" method="post">
<select onChange="JavaScript:check(this.form)" name="opt">
<option value="file1.php">1</option>
<option value="file1.php">2</option>
<option value="file2.php">3</option>
<option value="file2.php">4</option>
<option value="file3.php">5</option>
<option value="file3.php">6</option>
</select>
</form>

<script language="JavaScript">
function check() {
var number = document.form.opt.selectedIndex;
location.href = document.form.opt.options[number].value;
}
</script>

you can add as many options as you want without changing the script, just make sure that your option has the value of the file name that you want to go to.

matt

fyogi1
05-31-2005, 06:40 PM
Matt,
Thanks for your post. It is close but still fails. It goes to the correct php but does not pass the numeric value. I changed the variables on each php page to match the name "opt" The number are not in order, I say this because I am curious about the selectedIndex part of the JS.

Here is the code I have put in.
<form name="form" method="post">
<select onChange="JavaScript:check(this.form)" name="opt">
<option value="siteinfotemplate1.php">1</option>
<option value="siteinfotemplate1.php">2</option>
<option value="siteinfotemplate1.php">3</option>
<option value="siteinfotemplate1.php">7</option>
<option value="ngsinfotemplate1.php">300</option>
<option value="ngsinfotemplate1.php">305</option>
</select>
</form>

<script language="JavaScript">
function check() {
var number = document.form.opt.selectedIndex;
location.href = document.form.opt.options[number].value;
}
</script>


The change made on the php pages: (ngsinfotemplate1.php and siteinfotemplate1.php)
$tnumber = $_POST['opt'];

If you look at the last option, I need the number 305 to post to ngsinfotemplate1.php.


Thanks a lot for taking some time to look at this.
Frank



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum