In a drop down select field I pull several options based on a mysqli query
Once I select them, I use javascript to pick up the variables and infill form fields
Once I select the desired option, a form field infills with a reference number
I want to use that reference number for another select field to query the DB for a separate list
Here is the select to get the ref #
<select id="cdetail" name="cdetail"><option value="">Select</option>
<?
$mlo="SELECT * from client WHERE loan_originator ='$uname'";
$mlo_res = mysqli_query($dbc, $mlo);
while ($row = $mlo_res->fetch_assoc()){
echo "<option value=" . $row['filename'] . ">Filename: " . $row['filename'] . "</option>";
?>
</select>
Once I make the choice from the client table, I will see the filename in the 'cdetail' form field
I want to add another select field to pull from another table based on the selection in the above select option
<select id="ndetail" name="ndetail"><option value="">Select</option>
<?
$filename = $row['filename'];
$quote1="SELECT * from nclient WHERE filename ='$filename'";
$quote_res = mysqli_query($dbc, $quote1);
while ($row1 = $quote_res->fetch_assoc()){
echo "<option value=". $row1['ln_amt'] . ">Loan Amt: " . $row1['filename'] . "</option>";
?>
</select>
Trying to pull the filename from the 1st query and creating a global variable did not work the way I coded it.
I was able to use javascript to push the value into a separate field:
<script>
$('#cdetail').on('change', function () {
var x = $('#cdetail option:selected').val()
$('#flnm').val(x);
});
</script>
This will populate (on change) the flnm field with the filename, but I have not been able to grab that input and convert it into a php variable
i.e.
<? $filename = $('#flnm').val(x); ?>
or
<? $filename = ('#flnm').val(x); ?>
or
<? $filename = val(x); ?>
or
<? $filename = flnm; ?>