Hello good afternoon, sorry, I have a question, I want to add a button that when I clicked, add me N dynamic selects
This is the html that I have:
<h3>Origen: </h3>
<input type="hidden" name="">
<div class="input-group">
<span class="input-group-addon">Estado: </span>
<?php include_once("conexion.php");
$sql = $bd->query('SELECT * FROM estados');
if(filas($sql) > 0){ ?>
<select name="estados" id="estados" class="form-control">
<option value="0">Elegir</option>
<?php
while($dato = recorrer($sql)) { ?>
<option value="<?php echo $dato[1]; ?>"><?php echo $dato[2]; ?></option>
<?php } ?>
</select>
<?php }else{
echo "<button>Agregar nuevo</button>";
}
?>
</div>
<div class="input-group">
<span class="input-group-addon">Ciudad: </span>
<select id="municipios" name="municipios" class="form-control">
<option value="">...</option>
</select>
<span class="input-group-btn"><a href="localidad.php" role="button" class="btn btn-success"> + </a></span>
</div>
<h3>Destino: </h3>
<div class="input-group">
<span class="input-group-addon">Estado: </span>
<?php include_once("conexion.php");
$sql = $bd->query('SELECT * FROM estados');
if(filas($sql) > 0){ ?>
<select name="estados1" id="estados1" class="form-control">
<option value="0">Elegir</option>;
<?php
while($dato = recorrer($sql)) { ?>
<option value="<?php echo $dato[1]; ?>"><?php echo $dato[2]; ?></option>;
<?php }?>
</select>
<?php }else{
echo "<button>Agregar nuevo</button>";
}
?>
</div>
<div class="input-group">
<span class="input-group-addon">Ciudad: </span>
<select id="municipios1" name="municipios1" class="form-control">
<option value="">...</option>
</select>
I have this script:
<script type="text/javascript">
$(document).ready(function () {
$('#estados').change(function(event){
$('.load').fadeIn();
if($(this).val()!= '0'){
$.post('municipios.php', {'id_estado':$(this).val()}, function(data){
$('#municipios').html(''+data);
});
$('.load').fadeOut();
}else{
$('.load').fadeOut();
//a
}
});
$('#estados1').change(function(event){
$('#load').fadeIn();
if($(this).val()!= '0'){
$.post('municipios.php', {'id_estado1':$(this).val()}, function(data){
$('#municipios1').html(''+data);
});
$('#load').fadeOut();
}else{
$('#load').fadeOut();
//a
}
});
});
</script>
the code already works perfect for me, the doubt I have is how to add another select with the same data some advice
Of the respective first two dynamic selects that I have what I do not do, it is in a certain way to generate N dynamic selects, what I have not found is an example of it.
The module of the system that I am doing is of routes like this is the process