note 113816 deleted from function.pos by aharvey
| From: | aharvey@php.net | Date: | Thu, 05 Dec 2013 22:15:31 +0000 |
| Subject: | note 113816 deleted from function.pos by aharvey | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-197771@lists.php.net to get a copy of this message | ||
Note Submitter: sass
----
<!doctype html>
<html>
<head>
<title>Formulario</title>
<script type="text/javascript">
function validar() {
var f = document.forms[0];
// Validamos los campos obligatorios: Nombre, RUT y Edad.
if (f.nombre.value == "" || f.rut.value == "" || f.dv_rut.value ==
"" || f.edad.value == "") {
alert("Datos incompletos");
return false;
}
// Validamos el RUT.
if (/^[0-9]+$/.test(f.rut.value) == false || /^[0-9kK]$/.test(f.dv_rut.value) == false) {
alert("RUT incorrecto");
return false;
}
// Validamos que en caso de especificar dirección debe tener como mÃnimo calle, número
y ciudad.
// Si cualquier campo de la dirección tiene datos, entonces se quiere especificar una
dirección...
if (f.direccion_calle.value != "" || f.direccion_numero.value != "" ||
f.direccion_sector.value != "" || f.direccion_ciudad.value != "") {
// ... por lo tanto debe tener calle, número y ciudad como mÃnimo
if (f.direccion_calle.value == "" || f.direccion_numero.value == "" ||
f.direccion_ciudad.value == "") {
alert("Dirección incompleta");
return false;
}
}
// Validamos la edad.
if (/^[0-9]+$/.test(f.edad.value) == false) {
alert("Edad no válida");
return false;
}
if (f.edad.value < 18) {
alert("Sólo mayores de 18");
return false;
}
f.submit();
}
</script>
</head>
<body>
<h3>Calculo Plan de Salud</h3>
<form action="calcular_plan.php" method="post">
<table>
<tr><td>Nombre completo (*):</td><td><input type="text"
name="nombre" size="50" /></td></tr>
<tr><td>RUT (*):</td><td><input type="text"
name="rut" size="8" maxlength="8" /> - <input
type="text" name="dv_rut" size="1" maxlength="1"
/></td></tr>
<tr><td>Edad (*):</td><td><input type="text"
name="edad" size="3" maxlength="3" /></td></tr>
<tr><td colspan="2">Dirección</td></tr>
<tr><td>Calle:</td><td><input type="text"
name="direccion_calle" size="40" /></td></tr>
<tr><td>Número:</td><td><input type="text"
name="direccion_numero" size="5" /></td></tr>
<tr><td>Sector:</td><td><input type="text"
name="direccion_sector" size="40" /></td></tr>
<tr><td>Ciudad:</td><td><input type="text"
name="direccion_ciudad" size="20" /></td></tr>
<tr><td>Sexo:</td><td><select name="sexo"><option
value="f">Femenino</option><option
value="m">Masculino</option></select></td></tr>
<tr><td colspan="2"><input type="button" value="Calcular
Plan" onclick="validar()" /></td></tr>
</table>
</form>
(*): Datos obligatorios.
</body>
</html>