0
<tr>
      <td><strong>Department</strong></td>
      <td width="220" align="right">
       <select name="Depcategory"  dir="rtl" id="Depcategory" class="title">
                <option value="-1">chosse department</option>
              <?php
                $rs=$db->GetAllDepCategory($_SESSION["Faculty"]);
                while(list($name)=mysql_fetch_array($rs)){
                    echo "<option ".($DepSearch==$name?" selected=selected ":"")." value='$name'>$name</option>"; 
                    }


              ?>
        </select>
        </td>
        </tr>

     <tr> <td> <strong>Teacher name</strong></td>
      <td width="200" align="right"><label for="TeacheSearch"></label><select name="TeacheSearch"  dir="rtl" id="TeacheSearch" class="title">
        <option value="-1">choose teacher</option>
                <?php
                    $rs=$db->GetTeacher($_SESSION["Faculty"], $_SESSION["AdminWorkName"]);
                while(list($Fname,$WNO,$Lname)=mysql_fetch_array($rs)){
                    echo "<option ".($Lname==$TeacheSearch?" selected='selected' ":"")." value='$Lname'>$Fname $WNO</option>";
             }?>
        </select>
        </td>
        </tr>

Hello,
I've this code and i need to fix it so when i change the value of the first select, the values at the second select will change according to the value i did choose at the first select..

for example, if i've choosed IT as department from the first select, at the second select teachers at IT depramtent will be displayed.

"the values at both select are delievred from the database.."

thanks..

4
Contributors
6
Replies
37
Views
4 Years
Discussion Span
Last Post by paulkd
1

If you want to change the second select without a page refresh, then that's a Javascript issue. You'll need some AJAX code to retrieve the matching list, and a PHP script to provide that.

See this code snippet

0

Ajax is the solution for your problem. If you don't know how to program in JavaScript and Ajax you need to use "two steps" to achive your goal. so you have to create two pages each with a form and each form will "submit". pass a hidden value from the form in the first page and "catch" it in the second page, test it "on the fly" and depending on its value (the hidden one passed from the first page) the menu in the second form takes the proper value.

0

Using jQuery is the simplest method.
Before providing code I will explain the concept that you require.

  1. Your main php page will contain two select drop downs

  2. The first select is populated using your GetAllDept query. The second select will be empty

  3. You will have a second php page which will call your GetTeacher query and will simply display the results inside <option> tags like your original code. This second page is run something like www.yourwebsite.com/getteachers?deptcategory=itdepartment

  4. When the value of the first select is changed, JavsScript/jQuery is used to "quietly" run the second php file (with the value of the first select) and then inject the displayed <options> into your second empty select.

---

Page 1.
<select><option></option><option></option><option></option></select>
<select></select>

Page 2.
<option></option><option></option><option></option>

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.