I would like to select an option into a select list and trigger the code into the change function.
PHP request code :
$la_reservation = $dbh->prepare("SELECT *,
Date_debut, Date_fin,
client.Nom_societe, Personne_de_contact_idPersonne_de_contact,
IdAdresse, adresse.Rue, adresse.Numero, adresse.Boite, adresse.Code_postal, adresse.Localite, adresse.Pays, adresse.Email, Tel1, adresse.Client_IdClient
FROM bail
LEFT JOIN reservation ON idBail = Ref_bail
LEFT JOIN client ON bail.Ref_filiale = client.IdClient
LEFT JOIN personne_de_contact ON Personne_de_contact_idPersonne_de_contact = idPersonne_de_contact
LEFT JOIN adresse ON adresse.Client_IdClient = client.IdClient
WHERE idBail = :num_reservation");
$data = array(":num_reservation"=>$_GET['num_res']);
//echo str_replace(array_keys($data), array_values($data), $la_reservation->queryString);
$la_reservation->execute($data);
$res = $la_reservation->fetch();
I use $res[‘IdClient’] to indicate which option I want to select in the select list :
<script>$('#liste_clients').val("<?php echo $res['IdClient']?>");</script>
The generated code is :
<script>$('#liste_clients').val("14");</script>
but the alert in the change function is not working:
$("#liste_clients").change(function(){
alert("here");
....
}
Use
.on()event, Since the data is dynamically added into the page.