Voici le fichier index.php3
Code : Tout sélectionner
<?
session_start();
if (!isset($_SESSION['fois'])): $_SESSION['fois']=0; endif;
$_SESSION['fois']++;
print "Page affichée : $_SESSION[fois] fois.";
?>
<html>
<!-- Date de création: 16/09/2006 -->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title></title>
<script type="text/javascript" src="javascript.js"></script>
</head>
<body>
<form action="villes.php3" method="post" target="envdonne">
<table>
<tr>
<td>
Code Postal :
</td>
<td>
<select name="CP" onchange="this.form.submit();">
<option value="" selected> </option>
<option value="13127"> 13127</option>
<option value="13700"> 13700</option>
<option value="13500"> 13500</option>
</select>
</td>
</tr>
<tr>
<td align="right">
Ville :
</td>
<td id="ici">
<input type="text" name="ville" size="20" maxlength="256" value="Aucune ville">
</td>
</form>
</tr>
</table>
<br><br>
Rechargez la page en cliquant <a href="index.php3">ici<a>.
<script>
</script>
</body>
</html>
<iframe style="visibility: hidden; position: absolute" name="envdonne"></iframe>
Code : Tout sélectionner
function affichercode(code){
var ns4 = (document.layers)? true:false; /* Nescape 4 */
var ie4 = (document.all && !window.opera)? true:false; /* Internet Eplorer 4 */
var dom = (document.getElementById)? true:false; /* Nescape 6 ou Internet Eplorer 6 */
if (dom){document.getElementById("ici").innerHTML = code; return;}
if (ie4){document.all["ici"].innerHTML = code; return;}
if (ns4){ with (eval('document.'+"ici"+'.document')){open(); write(code); close();} return;}}
Code : Tout sélectionner
<?
if ($_POST['CP']=="13127"):
$ville="Vitrolles";
elseif ($_POST['CP']=="13700"):
$ville="Marignane";
elseif ($_POST['CP']=="13500"):
$ville="Martigues";
else:
$ville="Aucune ville";
endif;
print "<script>";
print "parent.affichercode('<input type=\"text\" name=\"ville\" size=\"20\" maxlength=\"34\" value=\"$ville\">');";
print "</script>";
?>
Bien sûre, c'est optimisable à souhait !!!
Bon je sais pas ce que ça vaut, mais moi ça me convient bien mieux que AJAX.
[email protected]