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

Recommended Answers

All 6 Replies

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

i tried many things befor, and didn't work..
don't know how to fix it : (

Do you know how to program in JavaScript?

no i don't actually : (

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.

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>

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.