Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Dynamic dropdown menus

Status
Not open for further replies.

mcmon999

IS-IT--Management
Mar 3, 2005
21
GB
Hi,

I have a form which contains three dropdown menus. The second is dependant on the first dropdown but i can get it to automatically reload the second menu without me having to pressing the submit button:

<form name="program_search" action="task_management.php" method="get" > </p>
<table width="40%">
<tr><td> <font face="century gothic" size="2" color="black">Select Enhancement:</td></font>
<td> <select name="enhancement"><font face="century gothic" size="2" color="black" onChange="javascript:document.program_search.submit()">
<?php
//Run query to get data to populate drop down with
$query0 = "select distinct enhancement from enhancement order by enhancement;";

$result = @mysql_query($query0, $connection) or die("Unable to find perform $critea query, <br>$query0");


//add results into an array
$row = mysql_fetch_array($result);

//asign values from array into a variable
$enhancementname = $row['enhancement'];


echo "<option value=\"All\"><font face='century gothic' size='2' color='black'>All</font></option>";

//Loop through rest of records. inserting into drop down
echo "<option value=\"$enhancementname\"><font face='century gothic' size='2' color='black'>$enhancementname</font></option>";

while ( $row =@ mysql_fetch_array($result) ) {
$enhancementname = $row['enhancement'];


//add the value into the box
echo "<option value=\"$enhancementname\"><font face='century gothic' size='2' color='black'>$enhancementname</font></option>";

}

?></tr> </td></font>

<tr><td> <font face="century gothic" size="2" color="black">Select Task:</td></font>
<td> <font face="century gothic" size="2" color="black"><select name="task">
<?php
$enhancement1 = $_GET['enhancement'];
//echo $enhancement1;
//Run query to get data to populate drop down with
$query7 = "select distinct task from enhancement where enhancement = '$enhancement1' order by task ;";
$result = @mysql_query($query7, $connection) or die("Unable to find perform $critea query, <br>$query7");


//add results into an array
$row = mysql_fetch_array($result);

//asign values from array into a variable
$taskname = $row['task'];


echo "<option value=\"All\"><font face='century gothic' size='2' color='black'>All</font></option>";

//Loop through rest of records. inserting into drop down
echo "<option value=\"$taskname\"><font face='century gothic' size='2' color='black'>$taskname</font></option>";

while ( $row =@ mysql_fetch_array($result) ) {
$taskname = $row['task'];


//add the value into the box
echo "<option value=\"$taskname\"><font face='century gothic' size='2' color='black'>$taskname</font></option>";

}

?></tr></td></font>
<tr><td> <font face="century gothic" size="2" color="black">Select Program:</td></font>
<td> <font face="century gothic" size="2" color="black"><select name="prog_id">
<?php

$user = $_SESSION['td_id'];

//Run query to get data to populate drop down with
$query8 = "select program_id, program from program where td_id = $user order by program;";
$result = @mysql_query($query8, $connection) or die("Unable to find perform $critea query, <br>$query8");


//add results into an array
$row = mysql_fetch_array($result);

//asign values from array into a variable
$programid = $row['program_id'];
$program = $row['program'];

echo "<option value=\"All\"><font face='century gothic' size='2' color='black'>All</font></option>";

//Loop through rest of records. inserting into drop down
echo "<option value=\"$programid\"><font face='century gothic' size='2' color='black'>$program ($programid)</font></option>";

while ( $row =@ mysql_fetch_array($result) ) {
$programid = $row['program_id'];
$programname = $row['program'];

//add the value into the box
echo "<option value=\"$programid\"><font face='century gothic' size='2' color='black'>$programname ($programid)</font></option>";

}
?>
</td></tr></font>


</table>
<input name="add_button" type="submit" value="Search">
<input type="reset" name="Reset" value="Reset"></p>
</p>
</form>

What i'd like it to do is display all tasks if enhancements is select to 'All' and automatically change the tasks dropdown if another an individual enhancement is selected.

Does anyone have any suggestions?

Thanks in advance.
 
Not With PHP alone. You need to actually submit the form for PHP to do its thing and populate the dropdown.

You could use Javascript to Submit the form automatically upon selection of an option. But of course thats Javascript territory and outside the scope of this forum.



----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
I just happen to have that code handy, so I can put it here...
Code:
<select name="DropDownListName" onchange="this.form.submit()" selected="YourVar">
You just need to save all the info and read it on reload. the onchange is the javascript that takes care of auto form submission. You're submit button must actually be named submit or else change it to this.form.YOURNAMEHERE
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top