So I am having some trouble with this code and need some help. I am not great at anything javascript related so this has thrown me for a loop. I have a select box with different locations. Based on the location the user chooses, an input box appears with a specific number. The php page works if I fill in the variable, but I cannot seem to get the variable to pass from one page to another.
Here is the front page callded Dropdown_test.php:
<body>
<label>
<span>Office Location</span><br>
<select name="office" id="office" onChange="loadDoc()">
<option value="">Select Office Location</option>
<option value="place1">Place 1</option>
<option value="place2">Place 2</option>
<option value="place3">Place 3</option>
<option value="place4">Place 4</option>
</select>
</label>
<div id="drawing"></div>
<script>
function loadDoc(){
var xhttp = new XMLHttpRequest();
var office = document.getElementsByName("office");
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200){
document.getElementById("drawing").innerHTML = this.responseText;
}
};
xhttp.open("GET", "fetch_details.php?=q" +office, true);
xhttp.send();
}
</script>
Here is the fetch_details page:
$office=$_GET['office'];
$rowSQL = mysqli_query($con, "SELECT MAX( DWG ) AS DWG FROM dwg WHERE
Office='$office';");
$row = mysqli_fetch_array($rowSQL);
$largestNumber = $row[ 'DWG' ];
$pieces = explode("-", $largestNumber);
$digit = $pieces[ 2 ] + 1;
$result = $pieces[ 0 ] . "-" . $pieces[ 1 ] . "-" . $digit;
echo "<input type='text' value='$result'></input>";
The fetch_page works just fine with the database, but when I combine them I get an undefined index. Any thoughts on where I am going wrong?
Thanks.