Afficher un tableau sur onchange d'un select
Bonjour,
Je cherche à afficher sur la même page un tableau (avec données provenant de MySQL) sur un onchange d'un select.
J'alimente un premier select, en fonction de ce premier j'en alimente un second et je voudrais que lors du choix de ce dernier un tableau soit affiché...
Pour les select j'utilise ajax, mais pour le select j'ai essayé mais je n'y parviens pas...
Mon code:
Code:
1 2 3
|
<label>Cellule:</label>
<select class="form-control" style="width:auto" id="cellule" name="cellule" onchange="loadpc(this.value)"></select><br> |
Partie ajax:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
|
<script type="text/javascript">
function loadpc(str) {
var id=cellule.options[cellule.selectedIndex].id;
alert(id);
if (str=="") {
document.getElementById("cellule").innerHTML="";
return;
}
if (window.XMLHttpRequest) {
// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
} else { // code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function() {
if (this.readyState==4 && this.status==200) {
document.getElementById("cellule").innerHTML=this.responseText;
}
}
alert(str);
//FAUT IL UTILISER LA METHODE GET OU POST???
xmlhttp.open("GET","toto.php?idcell="+cellule.options[cellule.selectedIndex].id, true);
xmlhttp.send();
//xhr.open("POST","ajax/toto.php",true);
//xhr.send("idcell="+cellule.options[cellule.selectedIndex].id);
}
</script> |
Merci par vance pour votre aide.