Results 1 to 2 of 2

Thread: Using value from a drop down list selection

  1. #1
    Join Date
    Jul 2007
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Using value from a drop down list selection

    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:

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

    mrtr33
    Last edited by mrtr33; 07-05-2007 at 11:30 PM.

  2. #2
    Join Date
    Jul 2007
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Solution

    Had some friends help me out....

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

    PHP Code:
    $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.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •