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
|
<?
echo "<input name='txtcodepostal' type='text' id='txtcodepostal' size='5' maxlength='5' value =$valcodepostal onblur='genere_liste(tableaucommunejs)'>";
?>
</font></td>
<td><font face="Verdana, Arial, Helvetica, sans-serif">
<?
function construisTableauJS($tableauPHP, $nomTableauJS)
{
echo $nomTableauJS." = new Array();";
for($i = 0; $i < count($tableauPHP); $i++){
if(!is_array($tableauPHP[$i])){
echo $nomTableauJS."[".$i."] = '".$tableauPHP[$i]."';";
}
else{
construisTableauJS($tableauPHP[$i], $nomTableauJS."[".$i."]");
}
}
return;
}
$requetecommune=mysql_query("SELECT * FROM COMMUNE");
$tableaucommune=array();
while($data = mysql_fetch_array($requetecommune))
{
$cp=$data['CPCOMMUNET'];
$commune=$data['NOMCOMMUNT'];
$tableaucommune[$cp]=$commune;
}
echo "<script language='JavaScript' type='text/JavaScript'>";
construisTableauJS($tableaucommune, "tableaucommunejs");
echo "</script>";
?>
<script language=JavaScript>
function genere_liste(tableau_cp)
{
var cp_cherche=document.getElementById('txtcodepostal').value;
var commune=tableau_cp[cp_cherche];
}
</script> |
Partager