Ver Mensaje Individual
  #2 (permalink)  
Antiguo 08/09/2008, 00:54
Avatar de KarlanKas
KarlanKas
Moderador extraterrestre
 
Fecha de Ingreso: diciembre-2001
Ubicación: Madrid
Mensajes: 6.987
Antigüedad: 23 años, 2 meses
Puntos: 61
Respuesta: Reglas en formulario según lo elegido en un select



<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Documento sin t&iacute;tulo</title>
<script>

function validar(f){

mal=false;
switch(f.estado_fono1.selectedIndex){
case 0:
alert("Por favor, seleccione un estado de fono");
mal=1;
break;
case 1:
if(f.codigo_1.value.length<2 || f.fono_1.value.length<6){
alert("El primer campo debe tener 2 cifras y el segundo 6");
mal=1;
}
else{
if(isNaN(f.codigo_1.value) || isNaN(f.fono_1.value)){
alert("Debe rellenar los dos campos con números!");
mal=1
}
}

break;
}
return !mal;
}
</script>
</head>

<body>
<form action="envio.php" onsubmit="return validar(this)">
<select name="estado_fono1">
<option value="">Elige opcion</option>
<option value="conecta">Conecta</option>
<option value="no-conecta">No Conecta</option>
</select>
<input type="text" name="codigo_1" maxlength="2" size="3" /><input size="7" type="text" name="fono_1" maxlength="6" /><br />
<br />
<input type="submit" value="Enviar" />
</form>
</body>
</html>
__________________
Cómo escribir

No hay pregunta tonta, sino tonto que quiere seguir en la ignorancia.