Good, as the question shows, I wanted to know if it is possible only with PHP since I see examples but they do it with JavaScript. I would appreciate if you could give an example to take it as a reference.
<?PHP
if(isset($_POST['enviar'])){
$nombre = $_POST['nombre'];
$apellidos = $_POST['apellidos'];
$edad = $_POST['edad'];
$provincia = $_POST['provincias'];
$dni = $_POST['dni'];
$sexo = $_POST['sexo'];
$cp = 0;
switch($provincia){
case "Palencia": $cp = 1010;
break;
case "Valladolid": $cp = 1020;
break;
case "Salamanca": $cp = 1030;
break;
case "Burgos": $cp = 1040;
break;
case "Avila": $cp = 1050;
break;
case "Soria": $cp = 1060;
break;
case "Segovia": $cp = 1070;
break;
case "Zamora": $cp = 1080;
break;
}
}
?>
<form action="<?PHP echo $_SERVER['PHP_SELF']?>" method="post">
<div>
<label for="nombre">Nombre</label>
<input type="text" name="nombre" size="15"><br/><br/>
<label for="apellido">Apellidos</label>
<input type="text" name="apellido" size="25"/><br/><br/>
<label for="edad">Edad</label>
<input type="text" name="edad" size="4"/><br/><br/>
<label for="proincias">Pais</label>
<select id="" name="provincias">
<option value = "Palencia">Palencia</option>
<option value = "Valladolid">Valladolid</option>
<option value = "Salamanca">Salamanca</option>
<option value = "Burgos">Burgos</option>
<option value = "Avila">Avila</option>
<option value = "Soria">Soria</option>
<option value = "Segovia">Segovia</option>
<option value = "Zamora">Zamora</option>
</select><br/><br/>
<label for="cp">CP</label>
<input type="text" name="cp" value="<?PHP ?>" size="10" disabled /><br/><br/>
<label for="dni">DNI</label>
<input type="text" name="dni" size="10"/><br/><br/>
<input type="radio" id="" name="sexo" value="hombre" />Hombre
<input type="radio" name="sexo" value="mujer" />Mujer<br/><br/>
<input type="submit" name="enviar"/>
</div>
</form>
</body>
What I try is that according to the fence, selecting each province shows me the province code but established in an input in which I call it CP (Postal Code). There in the value I was trying but leave it half XD