I have a form with a select input. I want to execute a jQuery function when the value of the select input changes:
This is the select input:
<div class="form-group required">
<label class="col-sm-3 control-label">Marca del vehículo</label>
<div class="col-sm-9">
<select class="form-control" name="marca" id="marca">
<option value="">Selecciona una marca de vehículo</option>
<?php
$sql = "SELECT * FROM car_make ORDER BY name ";
$res = $mysqli->query($sql);
while($row = $res->fetch_assoc())
{
echo"<option value=´{$row["id_car_make"]}']>{$row["name"]}
</option>";
}
?>
</select>
</div>
</div>
And this is the script that should launch the function when the select value changes:
<script>
if (window.jQuery) {
// jQuery is loaded
alert("Yeah!");
} else {
// jQuery is not loaded
alert("Doesn't Work");
}
$("#marca").change(function(){
cid = $(this).val();
$.post("modelo.php",{id:cid}, function(data){
$("#modelo").html(data);
});
});
I have included two alerts to confirm that jQuery is loaded.
Now, after changing the select value, the script is not launched.
I am not able to find the reason why the function is not launched