Foros del Web » Programación para mayores de 30 ;) » Java »

Problema con Java Script

Estas en el tema de Problema con Java Script en el foro de Java en Foros del Web. Buena amigos El problema que tengo es el siguiente, ese java script valida todos los datos del formulario, pero cuando un campo queda vacio el ...
  #1 (permalink)  
Antiguo 20/04/2008, 18:49
 
Fecha de Ingreso: abril-2008
Mensajes: 31
Antigüedad: 16 años
Puntos: 1
Problema con Java Script

Buena amigos

El problema que tengo es el siguiente, ese java script valida todos los datos del formulario, pero cuando un campo queda vacio el manda una alerta diciendo que el campo no deberia estar vacio (que es lo que tiene que hacer). Sin embargo despues de eso igual me abre la ventana de outlook (que no lo deberia hacer porque hay campos vacios).

<!DOCTYPE>
<html>
<head>
<title>REGISTRO DE CLIENTES</title>
<link rel="stylesheet" title="Nombre del CSS" type="text/css" href="estilos.css">
<meta http-equiv="Page-Exit" content="blendTrans(Duration=2.0)">
<script language="JavaScript">
//<!- para comentar si no es aceptado por el navegador
function validarForma(){
var chequeo=false;
if(chequear(document.f.Nombre))
if(chequear(document.f.Apellido))
if(chequearEmail(document.f.Email))
if(chequear(document.f.IdUsuario))
if(chequear(document.f.Clave))
if(chequear(document.f.Direccion))
if(chequearEdad(document.f.Edad))
if(chequearPais())
if(chequearCiudad())
chequeo=true;
if(chequeo)
alert("Gracias por registrarse en nuestra pagina");
else
return false;
}
//
function chequear(k){
if(k.value.length==0){
alert("Lo siento "+k.name+" no puede estar vacio");
k.focus();
return false;
}
else{ return true;}}
//
function chequearEmail(){
txt=document.f.Email.value;
a2=txt.indexOf("@");
len=txt.length;
if(a2<3) {
alert("Por favor corrija el Email");
document.f.Email.focus();
return false;
}
a3=txt.lastIndexOf(".");
checklast=len-a3;
if(checklast<3) {
alert("Por favor introduzca un Email valido");
document.f.Email.focus();
return false;
}
middot= txt.indexOf(".",a2);
len1=middot-a2;
if (len<1) {
alert("Por favor introduzca un Email valido");
document.f.Email.focus();
return false;
} else{
return true;}}

//
function chequearEdad(k) {
edad=document.f.Edad.value;
if(edad==""){
alert("Lo siento "+k.name+" no puede estar vacio");
k.focus();
return false;
}
if(isNaN(edad)){
alert("Lo siento "+k.name+" debe ser un numero valido");
document.f.Edad.focus();
return false;
}else{
return true;}}

//
function chequearPais() {
if (document.f.pais.selectedIndex==0){
alert("Debe escoger algun pais");
document.f.pais.focus();
return false;}
else{
return true;}}

function chequearCiudad() {
if (document.f.ciudad.selectedIndex==0){
alert("Debe escoger alguna ciudad");
document.f.ciudad.focus();
return false;}
else{
return true;}}

</script>

</head>


<body bgcolor="#EBEBFF">
<br>
<table>
<tr><td>
<embed src="formulario.swf" width="450" height="35"></td>
</tr><tr></tr>
</table>
<br>
<form name="f" method="post" enctype="text/plain" action="mailto:[email protected]">
<div id="foto" style="position:relative; left:0px; top:4px;">
<img src="Fotos/arribaregistro.jpg">
</div>

<table border="0" width="475" bgcolor="#CFCFFF">
<tr>
<td align="left"><font color="black">* Nombre:</font></td>
<td align="center"><input name="Nombre" size="35" maxlength="35" type="text"></td>
</tr>

<tr>
<td align="left"><font color="black">* Apellido:</font></td>
<td align="center"><input name="Apellido" size="35" maxlegth="35" type="text"></td>
</tr>

<tr>
<td align="left"><font color="black">* Email:</font></td>
<td align="center"><input name="Email" size="35" maxlegth="35" type="text"></td>
</tr>

</table>
<div id="foto" style="position:relative; left:0px; top:0px;">
<img src="Fotos/abajoregistro.jpg">
</div>
<br>
<div id="foto" style="position:relative; left:0px; top:4px;">
<img src="Fotos/arribaregistro.jpg">
</div>
<table align="center" border="0" width="475" bgcolor="#CFCFFF">
<tr>
<td align="left"><font color="black">* IdUsuario :</font></td>
<td align="center"><input name="IdUsuario" size="35" maxlegth="35" type="text"></td>
</tr>

<tr>
<td align="left"><font color="black">* Clave :</font></td>
<td align="center"><input name="Clave" size="10" maxlegth="10" type="password"></td>
</tr>
</table>
<div id="foto" style="position:relative; left:0px; top:0px;">
<img src="Fotos/abajoregistro.jpg">
</div>
<br>
<div id="foto" style="position:relative; left:0px; top:4px;">
<img src="Fotos/arribaregistro.jpg">
</div>
<table align="center" width="475" border="0" bgcolor="#CFCFFF">
<tr>
<td align="left"><font color="black">* Direccion :</font></td>
<td align="center"><input name="Direccion" size="35" maxlegth="100" type="text"></td>
</tr>

<tr>
<td align="left"><font color="black">* Edad </font></td>
<td align="center"><input name="Edad" size="3" maxlegth="3" type="text"></td>
</tr>

<tr>
<td align="left"><font color="black">* Sexo: </font></td>
<td align="center"><input name="SEXO" value="FEMENINO" checked="checked" type="radio"><font color="black">F <input name="SEXO" value="MASCULINO" type="radio"><font color="black">M</font></font></td>
</tr>

<tr>
<td align="left"><font color="black">* Pais </font></td>
<td align="center"><select name="pais">
<option value="eleccion">Pais de nacimiento</option>
<option value="Argentina">Argentina</option>
<option value="Brazil">Brazil</option>
<option value="Colombia">Colombia</option>
<option value="Venezuela">Venezuela</option>
<option value="Otro">Otro</option>
</select></td>
</tr>

<tr></tr>

<tr>
<td align="left"><font color="black">* Ciudad </font></td>
<td align="center"><select name="ciudadad">
<option value="eleccion">Ciudad de Nacimiento</option>
<option value="Buenos Aires">Buenos Aires</option>
<option value="Rio de Janeiro">Rio de Janeiro</option>
<option value="Bogot�>Bogot�/option>
<option value="Caracas">Caracas</option>
<option value="Otro">Otro</option>
</select></td>
</tr>
</table>
<div id="foto" style="position:relative; left:0px; top:0px;">
<img src="Fotos/abajoregistro.jpg">
</div>
<br>
<div id="foto" style="position:relative; left:0px; top:5px;">
<img src="Fotos/arribaregistro.jpg">
</div>
<table border="0" width="475" bgcolor="#CFCFFF">
<tr>
<td align="center"><input value="REGISTRATE" onClick="validarForma()" type="submit"></td>
<td align="center"><input value="LIMPIAR" type="reset"></td>
</tr>
</table>
<div id="foto" style="position:relative; left:0px; top:0px;">
<img src="Fotos/abajoregistro.jpg">
</div>
</form>

<br><br>
</body>
</html>
  #2 (permalink)  
Antiguo 21/04/2008, 03:32
 
Fecha de Ingreso: octubre-2003
Mensajes: 3.578
Antigüedad: 20 años, 6 meses
Puntos: 51
Re: Problema con Java Script

JavaScript no es Java. Te podrán ayudar mejor en un foro de JavaScript.


S!
__________________
Para obtener respuestas, pregunta de forma inteligente o si no, pregunta lo que quieras que yo contestaré lo que me dé la gana.
  #3 (permalink)  
Antiguo 22/04/2008, 22:05
Avatar de anubisdp  
Fecha de Ingreso: abril-2008
Mensajes: 12
Antigüedad: 16 años
Puntos: 0
Re: Problema con Java Script

<input value="REGISTRATE" onClick="validarForma()" type="submit">

ponle return antes de validarFormulario ejemplo:

<input value="REGISTRATE" onClick="return validarForma()" type="submit">

y asegurate que la funcion validarForma() retorne un false si no cumple con algun cliterio de lo contrario returna true, al regresar el false no se lanza el submit.

saludos
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 19:13.