Foros del Web » Programando para Internet » Javascript »

Cual es el error

Estas en el tema de Cual es el error en el foro de Javascript en Foros del Web. Hola gente copie esto del faq y lo modifique un poco pero no me funciona y no logro sacar el error. La idea es que ...
  #1 (permalink)  
Antiguo 07/05/2004, 08:53
cmc
 
Fecha de Ingreso: febrero-2003
Ubicación: Capital
Mensajes: 1.317
Antigüedad: 21 años, 2 meses
Puntos: 1
Cual es el error

Hola gente copie esto del faq y lo modifique un poco pero no me funciona y no logro sacar el error.
La idea es que verifique los campos y si son correctos que continue, una validacion comun.


function comprobar(){
errores="";
ok=1;
for(a=0;a<regla.length;a++){
valor=document.forms[0].elements[a].value;
if(eval(regla[a])){
ok=0;
errores+=mensaje[a]+"--";
document.forms[0].elements[a].style.background=colorMal;
herror.style.background=(errores!="")?colorBien:co lorMal;
herror.style.border=(errores!="")?"solid 1px black":"none";
herror.innerHTML="Verifique:"+errores;
}else{
document.forms[0].elements[a].style.background=colorBien;
}//fin del if
}//fin for
if (ok==1){
document.forms[0].elements[a].style.background=colorMal;
herror.style.background=(errores!="")?colorBien:co lorMal;
herror.style.border=(errores!="")?"solid 1px black":"none";
herror.innerHTML="Su mensaje esta siendo transferido, muchas gracias";

return false;
}else{
return true;
}
}

spero sus comentarios y ayudas
  #2 (permalink)  
Antiguo 07/05/2004, 09:13
Avatar de PatomaS
Colaborador
 
Fecha de Ingreso: marzo-2004
Ubicación: En alguna otra parte
Mensajes: 4.656
Antigüedad: 20 años, 1 mes
Puntos: 63
Hola

Bueno, parece que esta no es toda la función.

Si hay más elementos fuera de ella, no hay mucho problema, pero si esto es todo...

¿de dónde sale el contenido de regla.length?

esta línea:

for(a=0;a<regla.length;a++){

Tambien debes haber creado con una unión de cadenas una línea que quieres ejecutar llamada regla, pero no la veo.

esta línea:

if(eval(regla[a])){

Parece que el tema va por ahí, según sigo revisando, sigo viendo cosas referenciadas pero que no están allí.

Ya nos dirás si es que no las pegaste aquí o si es que no las tienes.

Suerte

Felicidad
__________________
¡ hey, hou, hou, hey !
  #3 (permalink)  
Antiguo 07/05/2004, 09:18
cmc
 
Fecha de Ingreso: febrero-2003
Ubicación: Capital
Mensajes: 1.317
Antigüedad: 21 años, 2 meses
Puntos: 1
Perdon pense que con esto era suficiente, aca coloco lo que falta
Vuelvo a hacer incapie en que el problema es que no valida, osea pinta los campos, los despinta y retorna al principio

colorMal="#ff9900";
colorBien="white";
ok=0;

regla=new Array()
regla[0]="valor.length<3";
regla[1]="valor.length<3";
regla[2]="valor.length<3";
regla[3]="";
regla[4]="";
regla[5]="valor.length<3";
regla[6]="";
regla[7]="valor.lastIndexOf('@')!=valor.indexOf('@') || valor.indexOf('@')<2 || valor.lastIndexOf('.')<valor.length-4 || valor.lastIndexOf('.')>valor.length-3";

mensaje=new Array()
mensaje[0]="El mensaje";
mensaje[1]="Su Nombre";
mensaje[2]="Su Apellido";
mensaje[3]="";
mensaje[4]="";
mensaje[5]="El número de teléfono introducido no es válido";
mensaje[6]="";
mensaje[7]="Correo inválido";
  #4 (permalink)  
Antiguo 07/05/2004, 18:56
cmc
 
Fecha de Ingreso: febrero-2003
Ubicación: Capital
Mensajes: 1.317
Antigüedad: 21 años, 2 meses
Puntos: 1
ayuda!!!
  #5 (permalink)  
Antiguo 08/05/2004, 07:03
Avatar de tunait
Moderadora
 
Fecha de Ingreso: agosto-2001
Ubicación: Terok Nor
Mensajes: 16.805
Antigüedad: 22 años, 8 meses
Puntos: 381
Deja el código entero del documento, incluyendo el formulario con el que no funciona
  #6 (permalink)  
Antiguo 08/05/2004, 11:00
cmc
 
Fecha de Ingreso: febrero-2003
Ubicación: Capital
Mensajes: 1.317
Antigüedad: 21 años, 2 meses
Puntos: 1
<?php require_once('Connections/cnn.php'); ?>
<?php
//FUNCION PARA FORMATEAR ENTRADAS, LLAMADA ANTES DE INSERTAR EN LA BASE DE DATOS
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
$theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $theValue; // si no esta habilitado magic cuotes, se agregan slashes

switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; //si es una cadena, se agregan comillas para la insercion SQL
break;
case "long":
$theValue = $theValue;//redundante, pero seguro
break;//hacia falta este BREAK
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}

if ((isset($HTTP_POST_VARS["MM_insert"])) && ($HTTP_POST_VARS["MM_insert"] == "form1")) {
$insertSQL = sprintf("INSERT INTO emisores (mensaje, nombre, apellido, te_cod_area, te_num, te_cel, email, empresa) VALUES (%s, %s, %s, %s, %s, %s, %s, %s)",
GetSQLValueString($HTTP_POST_VARS['mensaje'], "text"),
GetSQLValueString($HTTP_POST_VARS['nombre'], "text"),
GetSQLValueString($HTTP_POST_VARS['apellido'], "text"),
GetSQLValueString($HTTP_POST_VARS['te_cod_area'], "double"),
GetSQLValueString($HTTP_POST_VARS['te_num'], "double"),
GetSQLValueString($HTTP_POST_VARS['te_cel'], "double"),
GetSQLValueString($HTTP_POST_VARS['email'], "text"),
GetSQLValueString($HTTP_POST_VARS['empresa'], "text"));

mysql_select_db($database_cnn, $cnn);
$Result1 = mysql_query($insertSQL, $cnn);
if($Result1){
$exito = 1;
}else{
$exito = 0;
}
}
?>
<html>
<head>
<title>***Water Net***</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link href="stilos.css" rel="stylesheet" type="text/css">
</head>
<script>
colorMal="#ff9900";
colorBien="white";

//ok=0;

regla=new Array()
regla[0]="valor.length<3";
regla[1]="valor.length<3";
regla[2]="valor.length<3";
regla[3]="";
regla[4]="";
regla[5]="valor.length<3";
regla[6]="";
regla[7]="valor.lastIndexOf('@')!=valor.indexOf('@') || valor.indexOf('@')<2 || valor.lastIndexOf('.')<valor.length-4 || valor.lastIndexOf('.')>valor.length-3";

mensaje=new Array()
mensaje[0]="El mensaje";
mensaje[1]="Su Nombre";
mensaje[2]="Su Apellido";
mensaje[3]="";
mensaje[4]="";
mensaje[5]="El número de teléfono introducido no es válido";
mensaje[6]="";
mensaje[7]="Correo inválido";

function cerrar(exito){
alert("SI ENTRE A LA FUNCION CERRAR!");
//localizacion = opener.location;
//actual = localizacion.replace('#','');
actual = "index.php";
menfalla = actual+"?hola=20";
menexito = actual+"?hola=10";
if(exito == 1){
opener.location = menexito;
}else{
opener.location = menfalla;
}
window.close();
}
function limpiar(){
for(a=0;a<regla.length;a++){
document.forms[0].elements[a].style.background=colorBien;
herror.style.background=(errores!="")?colorBien:co lorMal;
herror.style.border=(errores!="")?"solid 1px black":"none";
herror.innerHTML="Para una mejor comunicacion la empresa le sugiere llenar todos los campos";
}
}
function comprobar(){
errores="";
for(a=0;a<regla.length;a++){
valor=document.forms[0].elements[a].value;
if(eval(regla[a])){
ok=1;
errores+=mensaje[a]+"--";
document.forms[0].elements[a].style.background=colorMal;
herror.style.background=(errores!="")?colorMal:col orBien;
herror.style.border=(errores!="")?"solid 1px black":"none";
herror.innerHTML="Verifique:"+ errores;
}else{
ok=0;
document.forms[0].elements[a].style.background=colorBien;
}//fin del if

}//fin for
alert(ok);
if (ok==0){
document.forms[0].elements[a].style.background=colorBien;
herror.style.background=(errores!="")?colorMal:col orBien;
herror.style.border=(errores!="")?"solid 1px black":"none";
herror.innerHTML="Su mensaje esta siendo transferido, muchas gracias";
//return false;
}else{
alert("Desde aca vuelve a cero, y no es por el return true");
//return true;
}

}//fin función comprobar
</script>
<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0"<?php echo isset($exito) && $exito==1 ? 'onLoad="cerrar('.$exito.');"' : '';//echo isset($exito)? ' onLoad="cerrar('.$exito.');"' : ''; ?>>
<table width="500" height="250" border="0" align="left" cellpadding="0" cellspacing="0" background="centro.gif">
<tr>
<td width="589" height="280" align="center" valign="middle">
<table width="529" height="195" align="center" cellpadding="0" cellspacing="0">
<tr>
<td></td>
</tr>
<tr>
<td width="527" height="10" align="center" valign="middle" class="Titulo"><div align="left">::Contactenos::
</div></td>
</tr>
<tr>
<td width="500" height="250" align="center" valign="middle">
<form action="" method="post" name="form1" onReset="return limpiar()">
<table width="454" height="245" align="center">
<tr>
<td height="23" colspan="3" align="right" valign="baseline" nowrap class="texto">&nbsp;</td>
<td width="126" colspan="2" rowspan="9" valign="baseline" class="texto">
<div align="center">Mensaje:
<textarea name="mensaje" cols="32" class="cjadiaogo"></textarea>
</div></td>
</tr>
<tr>
<td width="85" align="right" valign="baseline" nowrap class="texto">Nombre:</td>
<td width="160" colspan="2" valign="baseline"> <input name="nombre" type="text" class="cajas" value="" size="32"></td>
</tr>
<tr>
<td align="right" valign="baseline" nowrap class="texto">Apellido:</td>
<td colspan="2" valign="baseline"> <input name="apellido" type="text" class="cajas" value="" size="32"></td>
</tr>
<tr>
<td align="right" valign="baseline" nowrap class="texto">Empresa:</td>
<td colspan="2" valign="baseline"> <input name="empresa" type="text" class="cajas" value="" size="32"></td>
</tr>
<tr>
<td rowspan="2" align="right" valign="middle" nowrap class="texto">Tel&eacute;fono</td>
<td valign="bottom" class="letrachica"> <div align="center">Cod</div></td>
<td class="texto"><div align="center" class="letrachica"><font color="#000099">Numero</font></div></td>
</tr>
<tr valign="baseline">
<td><input name="te_cod_area" type="text" class="CajaChica" value="" size="32"></td>
<td> <div align="right">
<input name="te_num" type="text" class="CajaMedia" value="" size="32">
</div></td>
</tr>
<tr>
<td align="right" valign="baseline" nowrap class="texto">Tel_cel:</td>
<td colspan="2" valign="baseline"> <input name="te_cel" type="text" class="CajaMedia" value="" size="32"></td>
</tr>
<tr>
<td align="right" valign="baseline" nowrap class="texto">E-mail:</td>
<td colspan="2" valign="baseline"> <input name="email" type="text" class="cajaemail" value="" size="32"></td>
</tr>
<tr>
<td colspan="3" rowspan="2" align="right" valign="baseline" nowrap>&nbsp;</td>
</tr>
<tr valign="baseline">
<td height="23" align="right"> <input name="Reset" type="reset" class="boton" value="Limpiar" id="Limpiar">
</td>
<td height="20" align="left"> <input name="button" type="submit" class="boton" id="Submit" value="Enviar" onClick="comprobar()">
</td>
</tr>
<tr align="center" valign="baseline" class="Pie">
<td width="450" height="30" colspan="5" id="herror"><div align="center">Para
una mejor comunicaci&oacute;n la empresa le sugiere llenar
todos los campos</div></td>
</tr>
</table>
<br>
<input type="hidden" name="MM_insert" value="form1">
</form></td>
</tr>
<tr>
<td width="527" height="5" valign="top"></td>
</tr>
</table>
</td>
</tr>
</table>
</body>
</html>
  #7 (permalink)  
Antiguo 08/05/2004, 11:05
Avatar de tunait
Moderadora
 
Fecha de Ingreso: agosto-2001
Ubicación: Terok Nor
Mensajes: 16.805
Antigüedad: 22 años, 8 meses
Puntos: 381
Hey, que con el php no puedo adivinar los valores y código que va a resultar, dame la parte que llega al cliente (navegdor)

ejecuta tu página, pide ver codigo fuente y dame ese resultado
  #8 (permalink)  
Antiguo 08/05/2004, 11:16
cmc
 
Fecha de Ingreso: febrero-2003
Ubicación: Capital
Mensajes: 1.317
Antigüedad: 21 años, 2 meses
Puntos: 1
a que te referis con la parte que llega al cliente, si te referis al cuerpo del documento, lo tenes.
  #9 (permalink)  
Antiguo 08/05/2004, 11:53
Avatar de tunait
Moderadora
 
Fecha de Ingreso: agosto-2001
Ubicación: Terok Nor
Mensajes: 16.805
Antigüedad: 22 años, 8 meses
Puntos: 381
Estás trabajando ese documento desde una popup?
  #10 (permalink)  
Antiguo 08/05/2004, 13:54
cmc
 
Fecha de Ingreso: febrero-2003
Ubicación: Capital
Mensajes: 1.317
Antigüedad: 21 años, 2 meses
Puntos: 1
Si
  #11 (permalink)  
Antiguo 10/05/2004, 09:33
cmc
 
Fecha de Ingreso: febrero-2003
Ubicación: Capital
Mensajes: 1.317
Antigüedad: 21 años, 2 meses
Puntos: 1
No se olviden de mi
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 09:33.