I have made a combo box that should return the bank account numbers of a bank, because a bank can have more than one account number registered, I am sending a query through AJAX to the database I have inserted an HTML in the option which shows the account number according to the selection of the User's bank, I attach the html code, the AJAX and the query. Please I appreciate your help.
<script type="text/javascript"> $(document).ready (function () {
$("#cbx_banco").change(function(){
$("#cbx_banco option:selected").each(function(){
var idbanco = fk_id_banco = $(this).val();
alert (idbanco);
var banco = fk_id_banco;
$.ajax({
type:"POST",
url:"getbankacounts.php",
data: banco,
success: function(data)
$("#cbx_counts").html(data);
})
});
});
});
</script>
This is the AJAX destination code where I make the query
<?php
require('conexion.php');
$fk_id_banco = $_POST['fk_id_banco'];
$queryCb = "select nr_Cuenta_bancaria from cuenta_bancaria where fk_id_Banco
= '$fk_id_banco' ";
$resultadoCb = $mysqli->query($queryCb);
$html = "<option value='0'>Seleccionar Cuenta </option>";
while ($opcionesCta = $resultadoCb->fecth_assoc()){
$html = "<option value =
'".$opcionesCta['nr_Cuenta_bancaria']."'>".
$opcionesCta['nr_Cuenta_bancaria']."</option>";
}
echo $html;
And this is the HTML fragment where you should show the account number according to what the user selects as a bank.
<select id="cbx_counts" class="custom-select" name="cbx_counts" >
<option value="">Nro Cuenta: </option>
<option value=""><?php $opciones['nr_Cuenta_bancaria'] ?></option>
</select>