I have a dropdown box "#pro" Which when selected will send a number to my php script "ft-customerpo.php". This php script should return the entries corresponding with this project number and display the results in another dropdown box named "#custponumhold".
My html:
<label for="txtfield">Project Number <b style="color:red;">*</b></label>
<select id="pro" name="projectnoid" class="inputvalues" required/>
<option disabled selected value>-- Project Number</option>
<?php echo $options_1; ?>
</select><br>
<label>Customer PO Number <b style="color:red;">*</b></label>
<select id="custponumhold" style="width: 250px;" name="custpo" class="inputvalues" required>
</select>
My Javascript:
//CHAINED COMBOBOX
$(document).ready(function() {
$('#pro').on('change', function() {
var project = $(this).val();
if (project) {
$.ajax({
type: 'POST',
url: 'ft-customerpo.php',
data: 'project=' + project,
success: function(html) {
$('#vendponum').html(html);
}
});
}
});
});
And "ft-customerpo.php"
<?php
require "../inc/dbinfo.inc";
$i=1;
$proj = mysqli_real_escape_string($_POST['projectnoid']);
if($proj)
{
$rs = $conn->query("SELECT PONumber
FROM tblCustomerPOs
WHERE ProjectNum = '$proj'");
$options[0] = "<option disabled selected value>-- Customer PO</option>";
while($row[$i] = $rs->fetch_assoc()) {
$options .= "<option value='".$row['PONumber']."'>".$row['PONumber']."
</option>";
$i++;
}
echo json_encode($options);
}
?>
Currently, when I change the project number it sends the request fine. But I do not get a response back. I think the problem is with my "ft-customerpo.php". Sorry if my logic does not make sense. The Customer PO dropdown (#custponumhold) does not display any options when it should.