Foros del Web » Programando para Internet » Javascript »

Enviar datos no vacios...evento onsubmit

Estas en el tema de Enviar datos no vacios...evento onsubmit en el foro de Javascript en Foros del Web. Muy buenas amigos, tengo el siguiente codigo el cual mi intencion es k valide el campo de texto "CANTIDAD", el cual permita enviar al formulario ...
  #1 (permalink)  
Antiguo 02/04/2009, 13:25
Avatar de hoberwilly  
Fecha de Ingreso: julio-2008
Ubicación: Lima - Perú
Mensajes: 769
Antigüedad: 15 años, 10 meses
Puntos: 2
Enviar datos no vacios...evento onsubmit

Muy buenas amigos, tengo el siguiente codigo el cual mi intencion es k valide el campo de texto "CANTIDAD", el cual permita enviar al formulario con datos (no vacio)...pero no me valida. En alguna parte estare errado?, quizas me puedan orientar.
Código php:
Ver original
  1. <!-- <html>
  2. <head>
  3. <title>CATALOGO ELLAS</title>
  4. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
  5. <script type="text/javascript">  
  6. function vacio(valor){
  7.     if(valor.value==""){
  8.         alert("Tiene que ingresar una cantidad!");
  9.         valor.focus();
  10.         return false;
  11.     }
  12.     return true;
  13. }
  14. </script>
  15. </head>
  16. <body>
  17. <table>    
  18. <tr>
  19.     <td>
  20.     <table>
  21.     <form name="form" method="post" action="agregacarElla.php?<?php echo SID ?>" onSubmit="return vacio(this);">
  22.     <tr>
  23.     <td>
  24.       <input type="text" name="cantidad" value="<?php echo $cantidad ?>" size="2" maxlength='4' onKeypress="return acceptNumNumero(this)">par(es)
  25.       <input type="hidden" name="id" value="<?php echo $row['id']; ?>">
  26.       <input type="hidden" name="pagina" value="<?php echo $pag ?>">
  27.     </td>
  28.     <td>&nbsp;<input name="imageField" type="image" src="img/icono-compras.gif" width="31" height="28" border="0" alt="Agregar al Carrito"></td>
  29.     </tr>
  30.     </form>
  31.     </table>
  32.     </td>
  33. </tr>
  34. </table>
  35. </body>
  36. </html>
  37.  -->

Muchas gracias por sus respuestas,
  #2 (permalink)  
Antiguo 02/04/2009, 13:32
Avatar de David
Moderador
 
Fecha de Ingreso: abril-2005
Ubicación: In this planet
Mensajes: 15.720
Antigüedad: 19 años
Puntos: 839
Respuesta: Enviar datos no vacios...evento onsubmit

Es que el parámetro que le estás mandando a tu función es el formulario, no el campo. Prueba así:
Código javascript:
Ver original
  1. return vacio(this.cantidad);
__________________
Por favor, antes de preguntar, revisa la Guía para realizar preguntas.
  #3 (permalink)  
Antiguo 02/04/2009, 13:45
Avatar de hoberwilly  
Fecha de Ingreso: julio-2008
Ubicación: Lima - Perú
Mensajes: 769
Antigüedad: 15 años, 10 meses
Puntos: 2
De acuerdo Respuesta: Enviar datos no vacios...evento onsubmit

Upsss.... Era eso efectivamente, muchas gracias David.

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 09:25.