View Full Version : Using value from a drop down list selection

07-04-2007, 07:48 PM
I have a class table where I want to access the names of courses and the description of each course. The names of the courses go in a drop down list. Based on the user selection, the description shows up as text beneath the drop down menu.

I have the following code:

$queryReq="SELECT name FROM class";
$resultReq = @mysql_query ($queryReq);
echo "<br><form action=index.php name='trouble' method='POST'><select name='class' >";
while($nt=mysql_fetch_array($resultReq)){echo "<option value=$nt[description]>$nt[name]</option>";}
echo "</select><submit type='button' name='go'/>";
$class = $_POST['class'];
echo "$class</form>";
echo "<br>";

How do I use the value of my option tag to display the user's choice in some fashion beneath it? I've mostly seen only static array options handle this problem.

I've tried to retrieve the selection using POST, also tried using an onchange function within the <select> tag.

Any help would be appreciated.


07-05-2007, 11:31 PM
Had some friends help me out....

Here is the solution, in case anyone else comes looking for it:

$queryReq="SELECT name, description FROM class";
$resultReq = mysql_query($queryReq);
echo "<br><form action=index.php name='trouble' method='POST'><select name='class' >";
while($nt = mysql_fetch_assoc($resultReq)){echo "<option value='".$nt['description']."'>".$nt['name']."</option>";}
echo "</select><input type='submit' value='Go'/><br>";
$class = $_POST['class'];
echo $class."</form><br>";

Hope it helps.