Hi, sorry for english, i have 3 select input , i want concatenate , by selecting a value of first select only some values are show in second select , the same for the third.
This is my html ,this code is for the first and second select :
Code:
<div class="col-md-4 text-center login_form">
<?= form_label('Regione*:' ,'regione',"class='black'") ;?>
<br>
<div class="form-group">
<div class="col-md-12 col-sm-12 col-xs-12">
<select id="regione_id" name="regione" >
<option value="" selected="selected">Regione --</option>
<?php foreach($regioni->result() as $regione) : ?>
<option value="<?php echo $regione->id ; ?>"><?php echo $regione->regione; ?></option>
<?php endforeach ; ?>
</select>
</div>
</div>
</div>
<div class="col-md-4 text-center login_form">
<p>
<?= form_label('Provincia*:' ,'provincia',"class='black'") ;?>
<br>
<div class="form-group">
<div class="col-md-12 col-sm-12 col-xs-12">
<select id="province_id" name="province" >
</select>
</div>
</div>
</p>
</div>
this is the ajax:
Code:
<script
src="https://code.jquery.com/jquery-3.2.1.min.js"
integrity="sha256-hwg4gsxgFZhOsEEamdOYGBf13FyQuiTwlAQgxVSNgt4="
crossorigin="anonymous"></script>
<script>
$(document).ready(function() {
$("#regione_id").change(function(){
var regione = $("#regione_id").val();
$.ajax({
type: "POST",
url: "<?php echo base_url(); ?>index.php/user/get_province",
data: "regione=1" ,
dataType: "html",
success: function(msg)
{
$("#province_id").html(msg);
},
error: function()
{
alert("Chiamata fallita, si prega di riprovare...");
}
});
});
});
</script>
this is the get_province() :
Code:
public function get_province(){
$regioni_id=$this->input->post('regione');
$query = $this->db->query("SELECT * FROM province WHERE id_regione= $regioni_id ");
echo '<option value="" selected="selected">-- seleziona --</option>';
foreach($query->result() as $province){
$id=$province->id;
$provincia=$province->provincia;
echo "<option value='$id'>$provincia</option>";
}
}
But when i change a value of first select i have error alert :
"Chiamata fallita, si prega di riprovare..."
how can i solve ?