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
| <html><head>
<script language="javascript">
function TestVille(obj)
{
var cp = obj.cp.value;
var ligne = "";
var cible = document.getElementById("CaseVille");
if (cp.length = 5) { cible.innerHTML = "<input type=\"text\" name=\"ville\" id=\"ville\" >"; }
if (cp.length < 5) { cible.innerHTML = "<input type=\"hidden\" name=\"ville\" value=\"\" >"; }
<?
//--on se connecte � MySQL-------------------
$dex_cte = mysql_connect('localhost','root','');
$dex_cte_db = mysql_select_db('idealeparut',$db);
$cte_command = mysql_query("SELECT FROM villes ORDER BY `code_postal` ASC", $dex_cte_db);
$cte = 0;
$cte_1 = "?";
$cte_max = mysql_num_rows($cte_command) - 1;
while ($cte <= $cte_max)
{
$cte_2 = mysql_result($cte_command,$cte,code_postal);
if ($cte != $cte_max)
{
$cte_3 = mysql_result($cte_command,($cte + 1),code_postal);
}
else
{
$cte_3 = "";
}
if (($cte_1 == $cte_2) and ($cte_2 == $cte_3))
{
echo "ligne += \"<option value=\\\"" . mysql_result($cte_command,$cte,nom_ville) . "\\\">" . mysql_result($cte_command,$cte,nom_ville) . "</option>\\\"; ";
}
if (($cte_1 == $cte_2) and ($cte_2 != $cte_3))
{
echo "ligne += \"<option value=\\\"" . mysql_result($cte_command,$cte,nom_ville) . "\\\">" . mysql_result($cte_command,$cte,nom_ville) . "</option>\"; ligne += \"</select>\"; ligne += \"<BR> autre ? <input type=\\\"text\\\" name=\\\"ville\\\" id=\\\"new_ville\\\" size=\\\"18\\\" value=\\\"\\\">\"; cible.innerHTML = ligne; } ";
}
if (($cte_1 != $cte_2) and ($cte_2 == $cte_3))
{
echo "if (cp == " . $cte_2 . ") { ligne += \"<select name=\\\"ville\\\">\"; ligne += \"<option value=\\\"" . mysql_result($cte_command,$cte,nom_ville) . "\\\">" . mysql_result($cte_command,$cte,nom_ville) . "</option>\"; ";
}
if (($cte_1 != $cte_2) and ($cte_2 != $cte_3))
{
echo "if (cp == " . $cte_2 . ") { cible.innerHTML = \"<input type=\\\"text\\\" name=\\\"ville\\\" id=\\\"ville\\\" size=\\\"20\\\" value=\\\"" . mysql_result($cte_command,$cte,nom_ville) . "\\\">\"; } ";
}
$cte_1 = $cte_2;
$cte_2 = $cte_3;
$cte++;
}
mysql_free_result($cte_command);
?>
}
</script>
</head><body><input name="cp" value="" size="5" onkeyup="TestVille(this.form)" type="text"><table><tbody><tr><td id="CaseVille" align="right" valign="top"></td></tr></tbody></table>
</body></html> |
Partager