HELP: change second select menu depending on first selection in javascript/ php

Discussion in 'PHP' started by JoeyWong, Oct 19, 2010.

  1. #1
    Hi all, what i want to do is when I select institution A, then the school of institution A come out at the second selection only.. when I select institution B, then the school of institution B come out at second the selection...etc
    Help...Thanks~

    <?php $sql = "SELECT DISTINCT i_name FROM school";
    // execute query
    $result = mysql_query($sql);
    if(isset($_POST["InstitutionName"]))
    $InstitutionName = $_POST["InstitutionName"];
    echo"<select name='InstitutionName'>";
    while ($row = mysql_fetch_array($result))
    { $i_name=$row["i_name"];
    echo"<option value='$i_name'";
    if (isset($InstitutionName) && $InstitutionName == $i_name)
    echo " selected> $i_name";
    else echo "> $i_name"; }
    echo "</select><br>"; ?>
    </td>
    </tr>
    <tr valign="baseline">
    <td nowrap="nowrap" align="left">School Name</td>
    <td>:</td>
    <td>School of &nbsp;
    <?php $sql = "SELECT DISTINCT s_name from school";
    // execute query
    $result = mysql_query($sql);
    if(isset($_POST["SchoolName"]))
    $SchoolName = $_POST["SchoolName"];
    echo"<select name='SchoolName'>";
    while ($row = mysql_fetch_array($result))
    { $s_name=$row["s_name"];
    echo"<option value='$s_name'";
    if (isset($SchoolName) && $SchoolName ==$s_name)
    echo " selected> $s_name";
    else echo "> $s_name"; }
    echo "</select><br>"; ?>
    </td>
    </tr>
     
    JoeyWong, Oct 19, 2010 IP
  2. EricBruggema

    EricBruggema Well-Known Member

    Messages:
    1,740
    Likes Received:
    28
    Best Answers:
    13
    Trophy Points:
    175
    #2
    please use the code tag so your code is readable and second please tell us what isn't working? or what your problem realy is!
     
    EricBruggema, Oct 21, 2010 IP
  3. silviuks

    silviuks Peon

    Messages:
    43
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #3
    use onChange=.... <select name='ddlXXX' onChange="some_javascript_function(this.value)"> ... </select>
     
    silviuks, Oct 21, 2010 IP