The code is supposed to fetch the query result and display it according to the number written in the text box, i tried (onkeydown and onkeyup) and both didn't work, i have no idea why it is not working and what is my mistake.
HTML code:
<script>
        function showRoom(rid) {
            xmlhttp = new XMLHttpRequest();
            xmlhttp.open("GET", "getRoomAJAX.php?q="+rid, true);
            xmlhttp.send();
            xmlhttp.onreadystatechange = function () {
                if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
                    document.getElementById("txtHint").innerHTML = xmlhttp.responseText;
                }
            }
        }
    </script>
    <form> 
        <input type="text" name="rid" onkeydown="showRoom(this.value)">
    </form>
    <div id="txtHint">Room...</div>
getRoomAJAX.php code:
<?php
session_start();
ob_start();
$q = $_GET["q"];
$db = new Database();
$dbc = $db->getConnection();
if (!$dbc) {
    die('Could not connect: ' . mysql_error());
}
$query = "SELECT * FROM indvProj_room WHERE rid = '".$q."'";
$result = mysqli_query($dbc, $query);
//start creating the table HTML
if ($result) {
    echo "<table border='1' align='center' cellspacing = '2' cellpadding = '4' width='100%'>
          <tr>
          <th><b>Room ID</b></th>
          <th><b>Room Description</b></th>
          </tr>";
    while ($row = mysqli_fetch_array($result, MYSQLI_BOTH)) {
        echo "<tr>";;
        echo "<td>" . $_SESSION['adminRoomChoice'] = $row['rid'] . "</td>";
        echo "<td>" . $row['roomDesc'] . "</td>";
        echo "</tr>";
    }
    echo "</table>";
} else {
    echo '<p class="error">Sorry, cannot find the room, are you sure of the entered Room ID?</p>';
    echo '<p class = "error">' . mysqli_error($dbc) . '</p>';
}
?>
 
    