Foros del Web » Programando para Internet » Javascript »

problema al validar

Estas en el tema de problema al validar en el foro de Javascript en Foros del Web. hola!! no se si pueda incluir mi pregunta en esta categoría, pero agradezco toda la ayuda posible!! pasa que yo tengo mi formulario en php ...
  #1 (permalink)  
Antiguo 31/08/2011, 15:26
Avatar de JeMaGa  
Fecha de Ingreso: julio-2011
Ubicación: Bogota
Mensajes: 430
Antigüedad: 12 años, 9 meses
Puntos: 4
problema al validar

hola!! no se si pueda incluir mi pregunta en esta categoría, pero agradezco toda la ayuda posible!! pasa que yo tengo mi formulario en php común y corriente, el problema viene al validarlo, quiero validar los campos y lo he intentado de varias formas y no funciona, y pues no me sale error pero tampoco me valida no se por que!! y de validaciones no es que sepa mucho por que hasta ahora empiezo con este tema.

buen este es mi formulario

Código HTML:
Ver original
  1. <DOCTYPE html PUBLIC "- / / W3C / / DTD XHTML 1.0 Strict / / EN" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  2.  
  3. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="es" lang="es">
  4.  
  5.  
  6. <title>Crear Usuario</title>
  7.  
  8. </head>
  9.  
  10. <meta http-equiv="content-type" content="text/html;charset=iso-8859-1" />
  11.  
  12. <link type="text/css" rel="stylesheet" href="estilo.css">
  13.  
  14. <script language="javaScript">
  15.  
  16. function  Validar(form1){
  17.     if(document.form1.Nombre.value =="")
  18.     {
  19.     alert("Ingrese Nombre ");
  20.     return false;
  21.     }else {
  22.    
  23.     return true;
  24.     }
  25.     if (document.form1.Contrasena.value.lengt ==" ")
  26.     {
  27.     alert("Ingrese Contraseña");
  28.     return false;
  29.     }
  30.  
  31.     if(document.form1.Area.value.lengt ==" ")
  32.     {
  33.     alert("Ingrese Area");
  34.     return false;
  35.     }
  36.  
  37.     if(document.form1.Cargo.value.lengt ==" ")
  38.     {
  39.     alert("Ingrese Cargo");
  40.     return false;
  41.     }
  42. }
  43.  
  44.  
  45. <br>
  46.  
  47. <center><h2>INGRESO DE USUARIOS</h2></center>
  48.  
  49. <h3><center>Aqui se permite agregar usuarios, cuando sea necesario, todos los campos con un <font color="red"><b>*</b></font> son obligatorios</center></h3>
  50.  
  51. <center><form id="form1" action="InsertaUsuario.php" method="post" onsubmit="return Validar()">
  52.  
  53. <?php if (isset($sindatos)) echo $sindatos; ?>
  54.  
  55. <center><br><table border ='2'>
  56.  
  57. <tr>
  58.  
  59. <td>
  60.  
  61. <center><IMG SRC="imagenes/LOGO.jpg" WIDTH=120 HEIGHT=100></center>
  62.  
  63. <h3><center>USUARIO A INGRESAR</center></h3>
  64.  
  65. </td>
  66.  
  67. <td><br>
  68.  
  69. <center><h4><font color="red"><b>*</b></font> Nombre: <input type="text" name="Nombre" size="25" value="<?php if(isset($Nombre)) echo $Nombre ?>" /></h4></center>
  70.  
  71. <center><h4><font color="red"><b>*</b></font> Password: <input type="password" name="Contrasena" size="25" /></center></h4>
  72.  
  73. <center><h4><font color="red"><b>*</b></font> Area: <input type="text" name="Area" size="30" value="<?php if(isset($Area)) echo $Area ?>" /></center></h4>
  74.  
  75. <center><h4><font color="red"><b>*</b></font> Cargo: <input type="text" name="Cargo" size="29" value="<?php if(isset($Cargo)) echo $Cargo ?>" /></center></h4>
  76.  
  77. <p align="center"><input type="submit" value="AGREGAR"  name="Agregar"><br>
  78.  
  79. </td>
  80.  
  81. </tr>
  82.  
  83. <div align="center"><a href="MenuAdmi.php"><h3> Devlover </h3></a></div>
  84.  
  85.  
  86. </div>
  87.  
  88. </form></center>
  89.  
  90. </body>
  91.  
  92. </html>

Agradezco toda la ayuda posible!!
  #2 (permalink)  
Antiguo 31/08/2011, 15:30
Avatar de Monimo  
Fecha de Ingreso: noviembre-2007
Ubicación: Mexico Df
Mensajes: 742
Antigüedad: 16 años, 5 meses
Puntos: 69
Respuesta: problema al validar

mmm esto está bien???


Código:
 document.form1.Contrasena.value.lengt

No le falta una "h"?
__________________
La verdad es que lo que no quisiera dejar de hacer nunca (a parte de comer) es programar
  #3 (permalink)  
Antiguo 31/08/2011, 15:50
Avatar de Monimo  
Fecha de Ingreso: noviembre-2007
Ubicación: Mexico Df
Mensajes: 742
Antigüedad: 16 años, 5 meses
Puntos: 69
Respuesta: problema al validar

Bueno mira cambié tu código así:

Código:

 <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" xml:lang="es" lang="es">
*
<head>
*
<title>Crear Usuario</title>
*
</head>
*
<meta http-equiv="content-type" content="text/html;charset=iso-8859-1" />
*
<link type="text/css" rel="stylesheet" href="estilo.css">
*
<script language="javaScript">
*
function *Validar(form1){
	
	var yu=document.getElementById('yu');
* * if(yu.value =="")
* * {
* * alert("Ingrese Nombre ");
* * return false;
* * }else {
* * 
* * return true;
* * }
* * if (document.form1.Contrasena.value.length ==" ")
* * {
* * alert("Ingrese Contraseña");
* * return false;
* * }
*
* * if(document.form1.Area.value.length ==" ")
* * {
* * alert("Ingrese Area");
* * return false;
* * }
*
* * if(document.form1.Cargo.value.length ==" ")
* * {
* * alert("Ingrese Cargo");
* * return false;
* * }
}
</script>
*
<body>
*
<br>
*
<center><h2>INGRESO DE USUARIOS</h2></center>
*
<h3><center>Aqui se permite agregar usuarios, cuando sea necesario, todos los campos con un <font color="red"><b>*</b></font> son obligatorios</center></h3>
*
<center><form id="form1"  action= "" method="post" onsubmit="return Validar('form1')">
*
<?php if (isset($sindatos)) echo $sindatos; ?>
*
<center><br><table border ='2'>
*
<tr>
*
<td>
*
<center><IMG SRC="imagenes/LOGO.jpg" WIDTH=120 HEIGHT=100></center>
*
<h3><center>USUARIO A INGRESAR</center></h3>
*
</td>
*
<td><br>
*
<center><h4><font color="red"><b>*</b></font> Nombre: <input type="text" id="yu" name="Nombre" size="25" value="<?php if(isset($Nombre)) echo $Nombre ?>" /></h4></center>
*
<center><h4><font color="red"><b>*</b></font> Password: <input type="password" name="Contrasena" size="25" /></center></h4>
*
<center><h4><font color="red"><b>*</b></font> Area: <input type="text" name="Area" size="30" value="<?php if(isset($Area)) echo $Area ?>" /></center></h4>
*
<center><h4><font color="red"><b>*</b></font> Cargo: <input type="text" name="Cargo" size="29" value="<?php if(isset($Cargo)) echo $Cargo ?>" /></center></h4>
*
<p align="center"><input type="submit" value="AGREGAR" *name="Agregar"><br>
*
</td>
*
</tr>
*
<div align="center"><a href="MenuAdmi.php"><h3> Devlover </h3></a></div>
*
</table>
*
</div>
*
</form></center>
*
</body>
*
</html>

Ya sirve ...
__________________
La verdad es que lo que no quisiera dejar de hacer nunca (a parte de comer) es programar
  #4 (permalink)  
Antiguo 31/08/2011, 15:50
Avatar de JeMaGa  
Fecha de Ingreso: julio-2011
Ubicación: Bogota
Mensajes: 430
Antigüedad: 12 años, 9 meses
Puntos: 4
Respuesta: problema al validar

mira es que he visto tutoriasles y no me funciona, esto es lo ultimo que he intentado y no funciona.

Código HTML:
Ver original
  1. <DOCTYPE html PUBLIC "- / / W3C / / DTD XHTML 1.0 Strict / / EN" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  2.  
  3. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="es" lang="es">
  4.  
  5.  
  6. <title>Crear Usuario</title>
  7.  
  8. </head>
  9.  
  10. <meta http-equiv="content-type" content="text/html;charset=iso-8859-1" />
  11.  
  12. <link type="text/css" rel="stylesheet" href="estilo.css">
  13.  
  14. <script language="javaScript">
  15.  
  16. function  Validar(form1){
  17.     if(document.form1.Nombre.value =="")
  18.     {
  19.     alert("Ingrese Nombre ");
  20.     return false;
  21.     }
  22.     if (document.form1.Contrasena.value ==" ")
  23.     {
  24.     alert("Ingrese Contraseña");
  25.     return false;
  26.     }
  27.  
  28.     if(document.form1.Area.value ==" ")
  29.     {
  30.     alert("Ingrese Area");
  31.     return false;
  32.     }
  33.  
  34.     if(document.form1.Cargo.value ==" ")
  35.     {
  36.     alert("Ingrese Cargo");
  37.     return false;
  38.     }
  39. }
  40.  
  41.  
  42. <br>
  43.  
  44. <center><h2>INGRESO DE USUARIOS</h2></center>
  45.  
  46. <h3><center>Aqui se permite agregar usuarios, cuando sea necesario, todos los campos con un <font color="red"><b>*</b></font> son obligatorios</center></h3>
  47.  
  48. <center><form id="form1" action="InsertaUsuario.php" method="post" onsubmit="return Validar()">
  49.  
  50. <?php if (isset($sindatos)) echo $sindatos; ?>
  51.  
  52. <center><br><table border ='2'>
  53.  
  54. <tr>
  55.  
  56. <td>
  57.  
  58. <center><IMG SRC="imagenes/LOGO.jpg" WIDTH=120 HEIGHT=100></center>
  59.  
  60. <h3><center>USUARIO A INGRESAR</center></h3>
  61.  
  62. </td>
  63.  
  64. <td><br>
  65.  
  66. <center><h4><font color="red"><b>*</b></font> Nombre: <input type="text" name="Nombre" size="25" value="<?php if(isset($Nombre)) echo $Nombre ?>" /></h4></center>
  67.  
  68. <center><h4><font color="red"><b>*</b></font> Password: <input type="password" name="Contrasena" size="25" /></center></h4>
  69.  
  70. <center><h4><font color="red"><b>*</b></font> Area: <input type="text" name="Area" size="30" value="<?php if(isset($Area)) echo $Area ?>" /></center></h4>
  71.  
  72. <center><h4><font color="red"><b>*</b></font> Cargo: <input type="text" name="Cargo" size="29" value="<?php if(isset($Cargo)) echo $Cargo ?>" /></center></h4>
  73.  
  74. <p align="center"><input type="submit" value="AGREGAR"  name="Agregar"><br>
  75.  
  76. </td>
  77.  
  78. </tr>
  79.  
  80. <div align="center"><a href="MenuAdmi.php"><h3> Devlover </h3></a></div>
  81.  
  82.  
  83. </div>
  84.  
  85. </form></center>
  86.  
  87. </body>
  88.  
  89. </html>
  #5 (permalink)  
Antiguo 31/08/2011, 15:54
Avatar de Monimo  
Fecha de Ingreso: noviembre-2007
Ubicación: Mexico Df
Mensajes: 742
Antigüedad: 16 años, 5 meses
Puntos: 69
Respuesta: problema al validar

Asíngnale a tus inputs un id.
después asigna a variables

var uno=document.getelementbyid('elidqueasignasteacada input');

después:

if (uno.value=="")

le faltan ids a tus inputs
__________________
La verdad es que lo que no quisiera dejar de hacer nunca (a parte de comer) es programar
  #6 (permalink)  
Antiguo 31/08/2011, 15:55
Avatar de JeMaGa  
Fecha de Ingreso: julio-2011
Ubicación: Bogota
Mensajes: 430
Antigüedad: 12 años, 9 meses
Puntos: 4
Respuesta: problema al validar

vi tu código y no tampoco funciona!!
  #7 (permalink)  
Antiguo 31/08/2011, 15:56
Avatar de Monimo  
Fecha de Ingreso: noviembre-2007
Ubicación: Mexico Df
Mensajes: 742
Antigüedad: 16 años, 5 meses
Puntos: 69
Respuesta: problema al validar

Cita:
Iniciado por JeMaGa Ver Mensaje
mira es que he visto tutoriasles y no me funciona, esto es lo ultimo que he intentado y no funciona.


<center><form id="form1" action="InsertaUsuario.php" method="post" onsubmit="return Validar()">
Ah sí y ahí tienes que pasar como parámetro el id del formulario, si no por eso no evalúa nada:

"return Validar('form1')"
__________________
La verdad es que lo que no quisiera dejar de hacer nunca (a parte de comer) es programar
  #8 (permalink)  
Antiguo 31/08/2011, 15:57
Avatar de Monimo  
Fecha de Ingreso: noviembre-2007
Ubicación: Mexico Df
Mensajes: 742
Antigüedad: 16 años, 5 meses
Puntos: 69
Respuesta: problema al validar

Cita:
Iniciado por JeMaGa Ver Mensaje
vi tu código y no tampoco funciona!!
Sí funciona ¬¬ si dejas el nombre en blanco te sale un alert....
__________________
La verdad es que lo que no quisiera dejar de hacer nunca (a parte de comer) es programar
  #9 (permalink)  
Antiguo 01/09/2011, 06:16
Avatar de JeMaGa  
Fecha de Ingreso: julio-2011
Ubicación: Bogota
Mensajes: 430
Antigüedad: 12 años, 9 meses
Puntos: 4
Respuesta: problema al validar

cuando lo probe no funciono
  #10 (permalink)  
Antiguo 01/09/2011, 08:14
Avatar de Monimo  
Fecha de Ingreso: noviembre-2007
Ubicación: Mexico Df
Mensajes: 742
Antigüedad: 16 años, 5 meses
Puntos: 69
Respuesta: problema al validar

Bueno ya t funciona o no?
__________________
La verdad es que lo que no quisiera dejar de hacer nunca (a parte de comer) es programar
  #11 (permalink)  
Antiguo 01/09/2011, 08:37
Avatar de JeMaGa  
Fecha de Ingreso: julio-2011
Ubicación: Bogota
Mensajes: 430
Antigüedad: 12 años, 9 meses
Puntos: 4
Respuesta: problema al validar

nooo nada
  #12 (permalink)  
Antiguo 01/09/2011, 10:48
Avatar de Monimo  
Fecha de Ingreso: noviembre-2007
Ubicación: Mexico Df
Mensajes: 742
Antigüedad: 16 años, 5 meses
Puntos: 69
Respuesta: problema al validar

Cita:
Iniciado por JeMaGa Ver Mensaje
nooo nada
Mmm lo que pasa es que tu condición está mal, entonces. Fíjate, si yo escribo un nombre pero los demás campos los dejo vacíos no me va a sacar ningun "alert" cuando debería decirme que los demás están vacíos...y me regresa true leugo luego...lo que segun yo, hace que no valide lo demás. NO?
__________________
La verdad es que lo que no quisiera dejar de hacer nunca (a parte de comer) es programar
  #13 (permalink)  
Antiguo 01/09/2011, 10:55
Avatar de Monimo  
Fecha de Ingreso: noviembre-2007
Ubicación: Mexico Df
Mensajes: 742
Antigüedad: 16 años, 5 meses
Puntos: 69
Respuesta: problema al validar

Este funciona tal cual:

Código Javascript:
Ver original
  1. <DOCTYPE html PUBLIC "- / / W3C / / DTD XHTML 1.0 Strict / / EN" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  2. *
  3. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="es" lang="es">
  4. *
  5. <head>
  6. *
  7. <title>Crear Usuario</title>
  8. *
  9. </head>
  10. *
  11. <meta http-equiv="content-type" content="text/html;charset=iso-8859-1" />
  12. *
  13. <link type="text/css" rel="stylesheet" href="estilo.css">
  14. *
  15. <script language="javaScript">
  16. *
  17. function *Validar(form1){
  18.    
  19.     var nm=document.getElementById('nm');
  20.     var pwd=document.getElementById('pwd');
  21.     var Ar=document.getElementById('ar');
  22.     var Cr=document.getElementById('cr');
  23.     var sigo=false;
  24.    
  25.    
  26. * * if(nm.value =="")
  27. * * {
  28. * * alert("Ingrese Nombre ");
  29. sigo=false;
  30. * * }
  31. * *
  32. * *
  33.         if (pwd.value =="")
  34.     * * {
  35.     * * alert("Ingrese Contraseña");
  36.     sigo=false;
  37.     * * }
  38. *
  39. * * if(Ar.value =="")
  40. * * {
  41. * * alert("Ingrese Area");
  42. sigo=false;
  43. * * }
  44. *
  45. * * if(Cr.value=="")
  46. * * {
  47. * * alert("Ingrese Cargo");
  48. sigo=false;
  49. * * }
  50.  
  51. if(nm.value !="" & pwd.value != "" & ar.value != "" & cr.value !="")
  52. {
  53.     return true;
  54. }else{
  55.     return false;
  56. }
  57.  *
  58.  
  59. }
  60.  
  61.  
  62. </script>
  63. *
  64. <body>
  65. *
  66. <br>
  67. *
  68. <center><h2>INGRESO DE USUARIOS</h2></center>
  69. *
  70. <h3><center>Aqui se permite agregar usuarios, cuando sea necesario, todos los campos con un <font color="red"><b>*</b></font> son obligatorios</center></h3>
  71. *
  72. <center><form id="form1"  action= "InsertaUsuario.php" method="post" onSubmit="return Validar('form1')">
  73. *
  74. <?php if (isset($sindatos)) echo $sindatos; ?>
  75. *
  76. <center><br><table border ='2'>
  77. *
  78. <tr>
  79. *
  80. <td>
  81. *
  82. <center><IMG SRC="imagenes/LOGO.jpg" WIDTH=120 HEIGHT=100></center>
  83. *
  84. <h3><center>USUARIO A INGRESAR</center></h3>
  85. *
  86. </td>
  87. *
  88. <td><br>
  89. *
  90. <center><h4><font color="red"><b>*</b></font> Nombre: <input type="text" id="nm" name="Nombre" size="25" value="<?php if(isset($Nombre)) echo $Nombre ?>" /></h4></center>
  91. *
  92. <center><h4><font color="red"><b>*</b></font> Password: <input id="pwd" type="password" name="Contrasena" size="25" /></center></h4>
  93. *
  94. <center><h4><font color="red"><b>*</b></font> Area: <input id="ar" type="text" name="Area" size="30" value="<?php if(isset($Area)) echo $Area ?>" /></center></h4>
  95. *
  96. <center><h4><font color="red"><b>*</b></font> Cargo: <input type="text" id="cr" name="Cargo" size="29" value="<?php if(isset($Cargo)) echo $Cargo ?>" /></center></h4>
  97. *
  98. <p align="center"><input type="submit" value="AGREGAR" *name="Agregar"><br>
  99. *
  100. </td>
  101. *
  102. </tr>
  103. *
  104. <div align="center"><a href="MenuAdmi.php"><h3> Devlover </h3></a></div>
  105. *
  106. </table>
  107. *
  108. </div>
  109. *
  110. </form></center>
  111. *
  112. </body>
  113. *
  114. </html>
__________________
La verdad es que lo que no quisiera dejar de hacer nunca (a parte de comer) es programar

Última edición por Monimo; 05/09/2011 a las 09:31

Etiquetas: html, php, formulario, usuarios
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 12:32.