I try to create a dynamic / dependent select with ajaxx and this even though it generates return results, I can not give value to the html element. Here the code:
<script>
// Agarra el ajaxx de país.
$(document).ready(function(){
$('#paisselect').on('change',function(){
var pais=$('select#paisselect').find(":selected").val();
if(pais){
console.log(pais);
$.ajax({
data:{pais:pais},
type:'POST', //mandar variables como post o get
url:'config/database.php', //url que recibe las variables
dataType :'html',
success:function(html){
$("#region").html(html);
}
});
}
});
});
</script>
html:
<label for="region"> Estado/Region: </label>
<select class="form-control" id="exampleFormControlSelect2" value="">
PHP data query:
if(!empty($pais) && !empty($pais)){
$sql = "SELECT * FROM regiones where id_pais='.$pais.'";
$resultado_regiones = $conn->query($sql);
if($resultado_regiones->num_rows > 0)
{
while($rowsregiones = $resultado_regiones->fetch_object())
{
echo '<option>'.$rowsregiones->nombre.' </option';
}
}
}
Thankful I would be with the help.