I am trying to make an ajax request which would change the content of my select.
Here is my request :
$(function() {
$("#client").change(function() {
type: 'GET',
url: "jsonContacts.php",
dataType: "json",
data: {
q: $("#client").val()
},
success: function(data) {
document.form.contactClient.options.length=0;
document.form.contactClient.options[0]=new Option("Test", "test", true, false);
for(var i=0; i<data.length; i++) {
}
}
});
});
My form is :
<FORM name='devis' method='POST' action='ajoutDevisScript.php' id='form' onsubmit="return validateForm()" >
<p>
<label for="client">Client</label>
<input type='text' id='client' name='client' required>
</p>
<p>
<label for="contactClient">Contact client</label>
<SELECT name="contactClient" id="contactClient">
</SELECT>
</p>
</form>
I would like that when the text of 'client' change, the request change the data of my SELECT but, my test Option isn't displayed at all.
Thanks!
Aucun commentaire:
Enregistrer un commentaire