Voici une liste selectivemultiple !!!
Merci à Ryan pour son aide, pour ceux que ca intéresse, voici le script complet avec trois select box, vous pouvez en ajouter autant que désiré sur le même modèle !
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 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
| Fichier Ajax : ajax_req.js
return xhr;
}
function htmlData(url, qStr)
{
var xhr = getXhr();
xhr.onreadystatechange = function()
{
if(xhr.readyState == 4 && xhr.status == 200)
{
document.getElementById("txtResult").innerHTML= xhr.responseText
}
}
url=url+"?"+qStr;
url=url+"&sid="+Math.random();
xhr.open("GET",url,true) ;
xhr.send(null);
}
function htmlData2(url, qStr)
{
var xhr2 = getXhr();
xhr2.onreadystatechange = function()
{
if(xhr2.readyState == 4 && xhr2.status == 200)
{
document.getElementById("txtResult2").innerHTML= xhr2.responseText
}
}
url=url+"?"+qStr;
url=url+"&sid="+Math.random();
xhr2.open("GET",url,true) ;
xhr2.send(null);
}
function htmlData3(url, qStr)
{
var xhr3 = getXhr();
xhr3.onreadystatechange = function()
{
if(xhr3.readyState == 4 && xhr3.status == 200)
{
document.getElementById("txtResult3").innerHTML= xhr3.responseText
}
}
url=url+"?"+qStr;
url=url+"&sid="+Math.random();
xhr3.open("GET",url,true) ;
xhr3.send(null);
} |
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 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
| Fichier : index.php
<html>
<head>
<title></title>
<script src="ajax_req.js" type="text/javascript"></script>
</head>
<body>
<form method="post">
<select name="country" onchange="htmlData('city.php', 'ch='+this.value)" />
<?php
$db = mysql_connect('localhost', 'XXX', 'XXXXXX');
mysql_select_db('XXXXXX',$db);
$sql = 'SELECT id,cp FROM cp_ville';
$req = mysql_query($sql) or die('Erreur SQL !<br>'.$sql.'<br>'.mysql_error());
while($data = mysql_fetch_assoc($req))
{
echo '<option value="'.$data['cp'].'">'.$data['cp'].'</option>';
}
?>
</select>
<br>
<div id="txtResult"> <select name="cityList"><option></option></select> </div>
<br>
<select name="list_auto_marque" onchange="htmlData2('city.php', 'ch='+this.value)" />
<?php
$db = mysql_connect('localhost', 'XXX', 'XXXXXX');
mysql_select_db('XXX',$db);
$sql2 = 'SELECT id,cp FROM cp_ville';
$req2 = mysql_query($sql2) or die('Erreur SQL !<br>'.$sql2.'<br>'.mysql_error());
while($data2 = mysql_fetch_assoc($req2))
{
echo '<option value="'.$data2['cp'].'">'.$data2['cp'].'</option>';
}
?>
</select>
<br>
<div id="txtResult2"> <select name="list_auto_modele"><option></option></select> </div>
<br>
<select name="3" onchange="htmlData3('city.php', 'ch='+this.value)" />
<?php
$db = mysql_connect('localhost', 'XXX', 'XXXXXX');
mysql_select_db('XXX',$db);
$sql3 = 'SELECT id,cp FROM cp_ville';
$req3 = mysql_query($sql3) or die('Erreur SQL !<br>'.$sql3.'<br>'.mysql_error());
while($data3 = mysql_fetch_assoc($req3))
{
echo '<option value="'.$data3['cp'].'">'.$data3['cp'].'</option>';
}
?>
</select>
<br>
<div id="txtResult3"> <select name="list_auto_modele"><option></option></select> </div>
<input type="submit" />
</form>
</body>
</html> |
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
| Fichier : city.php
<select name="cityList">
<?php
$db = mysql_connect('localhost', 'XXX', 'XXXXXX');
mysql_select_db('XXX',$db);
$go=$_GET['ch'];
$test='50';
$sql = 'SELECT id,cp,ville FROM cp_ville WHERE cp='.$go.'';
//$sql = 'SELECT id,cp,ville FROM cp_ville';
$req = mysql_query($sql) or die('Erreur SQL !<br>'.$sql.'<br>'.mysql_error());
while($data = mysql_fetch_assoc($req))
{
echo '<option value="'.$data['id'].'">'.$data['ville'].'</option>';
}
?>
</select> |