No dropdown menu

So, I have this code here, and when I select the dropdown menu, it should show the ID in the popup message, because I added alert (). But instead, nothing is displayed in the message. Is there something wrong with my code?

 <?php
    include "..\subjects\connect3.php";
    //echo "Connection successs";

    $query = "SELECT * FROM programmes_list";
    $result = mysqli_query($link, $query);
    ?>

    <form name = "form1" action="" method=""post>
    <table>
    <tr>
    <td>Select Pragramme</td>
    <td><select id="programmedd" onChange="change_programme()">
    <option>select</option>
    <?php
    while($row=mysqli_fetch_array($result)){
        ?>
    <option value="<?php echo $row["ID"]; ?>"><?php echo $row["programme_name"]; ?></option>
    <?php
        }
        ?>
        </select></td>
        </tr>

        <tr>
            <td>Select intake</td>
            <td>
            <div id="intake">
            <select>
            <option>Select</option>
            </select>
            </div>
            </td>
        </tr>

        <tr>
            <td>Select Subjects</td>
            <td>
            <div id="subject">
            <select>
            <option>Select</option>
            </select>
            </div>
            </td>
        </tr>


    </table>
    </form>             

    <script type="text/javascript">
    function change_programme()
    {
        var xmlhttp=new XMLHttpRequest();
        xmlhttp.open("GET","ajax.php?programme="+document.getElementById("programmedd").value,false);
        xmlhttp.send(null);

        document.getElementById("intake").innerHTML=xmlhttp.responseText;

    }

    function change_intake(){
        alert(document.getElementById("intakedd").value);
    }
    </script>


//ajax.php
<?php
    $dbhost = 'localhost' ;
    $username = 'root' ;
    $password = '' ;
    $db = 'programmes' ;

    $link = mysqli_connect("$dbhost", "$username", "$password");

    mysqli_select_db($link, $db);

    $programme=$_GET["programme"];


if($programme!="")
{
    $res=mysqli_query($link, "select * from intakes where intake_no = $programme");
    echo "<select id='intakedd' onChange='change_intake()'>";

    while($value = mysqli_fetch_assoc($res))
    {

    echo "<option value='$row[ID]'>";
    echo $value["intake_list"];
    echo "</option>";
    }   
    echo "</select>";
}



    ?>

      

+3


source to share


1 answer


CHANGE THIS LINE

 echo "<option value='$row[ID]'>"; TO 

    echo "<option value=$value['ID']>"; OR 

    echo "<option value=".$value['ID'].">";

      



you used $ row istead $ value

0


source







All Articles