I am updating the back-end of my website using xmlhttp to dynamically update the information shown based on a dropdown selection. I was able to get it so that it will successfully show the different "data" based on the dropdown. My next step is where I am getting hung up.
Here is the initial xmlhttp.send() request on file "admin.php"
<script>
function showUser(str) {
if (str == "") {
document.getElementById("txtHint").innerHTML = "";
return;
} else {
if (window.XMLHttpRequest) {
// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp = new XMLHttpRequest();
} else {
// code for IE6, IE5
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
document.getElementById("txtHint").innerHTML = xmlhttp.responseText;
}
}
xmlhttp.open("GET","displaySQL.php?q="+str,true);
xmlhttp.send();
}
}
</script>
This sends to my displaySQL.php file. Using 1 of the 3 dropdown selections as an example, I have:
if ($tname == "WorkOrders") {
echo "<table>
<tr>
<th>Work Order Number</th>
<th>Work Status</th>
<th>Job Type/Stage</th>
</tr>";
if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
echo "<tr><td>".$row["id"]."</td><td>".$row["status"]."</td><td>".$row["mainttype"]."</td></tr>";
}
}
echo "<br><br>";
echo "<form name='newRow' METHOD='post' ACTION='q.php'>
Status of New Entry: <input type='text' value='Open' name='newStatus' /><br>
Type of Maintenance being completed: <input type='text' value='Software Maintenance' name='maintType' /><br>
<input type='submit' value='Add' name='newEntry' />
</form>";
}
This shows the data from my DB as well as the form on my browser. When I hit "submit" on the form. It does not do anything my q.php tells it to. My q.php does function when I use the old form of my admin.php (no xmlhttp version), but not once I add the "middle man".
Is there a better way I should be inserting the form? I do want it dynamic based on the dropdown because each of the 3 have different forms involved.
Thanks.
UPDATE - The "function" is being called during the drop down selection on admin.php
<form>
<select name="users" onchange="showUser(this.value)">
<option value="">Select a table:</option>
<option value="1">Appointments</option>
<option value="2">Services</option>
<option value="3">Status</option>
</select>
</form>
<br>
<div id="txtHint"><b>Please select a table to work with...</b></div>