Академический Документы
Профессиональный Документы
Культура Документы
TEMA:
Programa en javascript se solicite y valide una cedula
OBJETIVOS:
Validar campos nombre, apellido, telefono y cedula de un formulario
CODIGO FUENTE
Ejercicio 1
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Documento sin título</title>
<script language="javascript" type="text/javascript">
function validacion2(formulario) {
</script>
<style type="text/css">
<!--
.style1 {
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 12px;
color: #666666;
font-weight: bold;
}
.style2 {
color: #666666;
font-weight: bold;
font-family: Verdana, Arial, Helvetica, sans-serif;
}
-->
</style>
</head>
<body>
Ejercicio2
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>Validaciones</title>
<style type="text/css">
<!--
.style8 {
font-family: Verdana, Arial, Helvetica, sans-serif;
font-weight: bold;
color: #333333;
}
.style9 {color: #666666}
.style10 {font-family: Verdana, Arial, Helvetica, sans-serif; font-
size: 12px; font-weight: bold; color: #666666; }
-->
</style>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-
1"></head>
<body>
<div align="center">
<script language=javascript>
function validarFormulario(){
var isNotOk;
//validación nombre
document.getElementById("name").style.display="inline";
//window.document.formValidar.nombre.focus();
//return 0;
isNotOk=true;
}
else{
UNIVERSIDAD TÉCNICA DE AMBATO
ESPECIALIZACION EN DISEÑO Y ANIMACIÓN WEB
JAVASCRIPT
____________________________________________________________
Alumna:Monica Llumitasig
:Jose Caicedo
:Cristina Ochoa
document.getElementById("name").style.display="none";
//validación apellido
document.getElementById("lastName").style.display="inline";
//window.document.formValidar.apellido.focus();
//return 0;
isNotOk=true;
}
else{
document.getElementById("lastName").style.display="none";
}
//validación calle
document.getElementById("street").style.display="inline";
//window.document.formValidar.calle.focus();
//return 0;
isNotOk=true;
}
else{
document.getElementById("street").style.display="none";
}
document.getElementById("number").style.display="inline";
//window.document.formValidar.numero.focus();
//return 0;
isNotOk=true;
}
else{
document.getElementById("number").style.display="none";
}
UNIVERSIDAD TÉCNICA DE AMBATO
ESPECIALIZACION EN DISEÑO Y ANIMACIÓN WEB
JAVASCRIPT
____________________________________________________________
Alumna:Monica Llumitasig
:Jose Caicedo
:Cristina Ochoa
if (isNotOk){
return 0;
}
else{
window.document.formValidar.submit();
}
}
</script>
<br>
<table width="50%" border="1" cellpadding="5" cellspacing="0"
bordercolor="#999999">
<tr>
<td><div align="center" class="style9"><span class="style8"><br>
VALIDACIONES</span><br>
</div>
<form name="formValidar" >
<table align="center" bgcolor="#CCCCCC">
<tr>
<td width="58"><span class="style10"><br>
Nombre:</span></td>
<td width="144"><br>
<input type=text name="nombre" maxlength=20></td><td
width="31"><div id="name" style="display:none; color:red"> Nombre
inválido</div>
<br></td>
</tr>
<tr>
<td><span class="style10">Apellido:</span></td>
<td><input type=text name="apellido" maxlength=20></td>
<td><div id="lastName" style="display:none;
color:red"> Apellido inválido</div></td>
</tr>
<tr>
<td><span class="style10">Calle:</span></td>
<td><input type=text name="calle" maxlength=20></td>
<td><div id="street" style="display:none;
color:red"> Calle inválida</div></td>
</tr>
<tr>
<td><span class="style10">Número:</span></td>
<td><input type=text name="numero" maxlength=5 ></td>
<td><div id="number" style="display:none;
color:red"> Número inválido</div></td>
</tr>
<tr>
<td><input name="button" type=button
onClick="validarFormulario()" value=Enviar> </tr>
</td>
</table>
UNIVERSIDAD TÉCNICA DE AMBATO
ESPECIALIZACION EN DISEÑO Y ANIMACIÓN WEB
JAVASCRIPT
____________________________________________________________
Alumna:Monica Llumitasig
:Jose Caicedo
:Cristina Ochoa
<p> </p>
</form></td>
</tr>
</table>
<br>
</div>
</body>
</html>
Ejercicio 1
Ejercicio 2
UNIVERSIDAD TÉCNICA DE AMBATO
ESPECIALIZACION EN DISEÑO Y ANIMACIÓN WEB
JAVASCRIPT
____________________________________________________________
Alumna:Monica Llumitasig
:Jose Caicedo
:Cristina Ochoa
CONCLUSIONES
• Con la aplicación se valido los campos de cadena: nombre, telefono, correo.
• Se puso en práctica el contenido de la tercera clase de javascript
RECOMENDACIONES
• Configurar adecuadamente el navegador antes de correr el script
BIBLIOGRAFÍA
• Javascript Primera Clase.Tenemaza Marisol. Colsultado el 9 de diciembre del
2009. Disponible en [http://rmtenemazajava.blogspot.com/]