Hello community, I have the following problem, I need to fill select
with another select from ajax .
I explain myself: I have a select in this way in my file html
<div class="form-group mt-1">
<select class="form-control mt-1" id="frutas">
<option value="manzana">manzana</option>
<option value="uva">uva</option>
<option value="pera">pera</option>
</select>
</div>
<div class="form-group mt-1">
<!--este select es el que nececito llenar segun la fruta-->
<select class="form-control mt-1" id="clave-frutas">
</select>
</div>
What I need is to replace only the options
from ana call to ajax , for example I'm trying to do the following ...
file JS
$('#frutas').change(function(){
var category=$(this).val();
var url="ajax/select_category.php";
$.ajax({
url:url,
type:"POST",
data:{category:category}
}).done(function(data){
$("#clave-fruta").html(data);
})
})
and in my file select_category.php I have the following ..
<?php
$category=$_POST["category"];
if ($category=="pera"){ ?>
<option value="granada">granada</option>
<option value="metralleta">metralleta</option>
<option value="pistola">pistola</option>
<?php }elseif($category=="manzana"){?>
<option value="cervesa">cervesa</option>
<option value="vino">vino</option>
<option value="champaña">champaña</option>
<?php }elseif($category=="uva"){?>
<option value="informatica">informatica</option>
<option value="programacion">programacion</option>
<option value="diseño">diseño</option>
} ?>
at the time of the ajax return those options the strip out of the select ie I expect an input type select
normal, but I throw the options out as if they were plain text and come like this for example if I choose apple
cervesa
vino
champaña
How could I achieve what I need some solution that I am doing wrong? thanks in advance