Una pregunta algo tonta!!!

(1/2) > >>

Zeroql:
Buenas!!!

Bueno tengo un form  con 2 botones, cada uno hace una funcion diferente de post,
pero tengo una funcion en javascript para validar que los datos esten bien.
lo que necesito es que cuando se presione uno de los botones este valla y verifique segun la funcion y luego redirija a la pagina que se le pidio.

como puedo hacer esto?

bueno, un ejemplo vale mas que mil palabras.
 asi que aca dejo esto para ver que tengo que cambiar.


Código
<form action="post" method="get" name="datos">
       <table width="950" bordercolordark="#333333">
         <tr>
           <td width="102" align="right">Codigo:</td>
           <td width="305"><Input type="text" name="cod" size="5" maxlength="5" style="border-bottom-style: groove; border-bottom-width: 1px; border-bottom-color:#06C"></td>
           <td width="119" align="right">Tipo:</td>
           <td width="404"><Input type="text" name="tipo"  maxlength="20" size="20" style="border-bottom-style: groove; border-bottom-width: 1px; border-bottom-color:#06C"></td>
         </tr>
         <tr>
           <td align="right">Marca:</td>
           <td><Input type="text" name="marca" maxlength="20" size="20" style="border-bottom-style: groove; border-bottom-width: 1px; border-bottom-color:#06C"></td>
           <td align="right">Estado:</td>
           <td><select name="estado1" id="estado" style="border-bottom-style: groove; border-bottom-width: 1px; border-bottom-color:#06C">
             <option value="Disponible">Disponible</option>
             <option value="Agotado">Agotado</option>
             <option value="Oferta">Oferta</option>
             <option value="Descontinuado">Disponible</option>
           </select></td>
         </tr>
         <tr>
           <td align="right">Modelo:</td>
           <td><Input type="text" name="mod" size="20" maxlength="20" style="border-bottom-style: groove; border-bottom-width: 1px; border-bottom-color:#06C"></td>
           <td align="right">Oferta? (Y/N):</td>
           <td><Input type="text" name="oferta" size="5" maxlength="1" style="border-bottom-style: groove; border-bottom-width: 1px; border-bottom-color:#06C"></td>
         </tr>
         <tr>
           <td align="right">Imagen:</td>
           <td><Input type="file" name="img"></td>
           <td align="right">Fin Oferta:</td>
           <td><Input type="date" name="fecha" size="20"  style="border-bottom-style:groove; border-bottom-width:1px; border-bottom-color:#06C"></td>
         </tr>
         <tr>
           <td align="right">Descripcion:</td>
           <td rowspan="2"><textarea name="desc" id="desc" cols="30" rows="3" maxlength="255" style="border-bottom-style:groove; border-bottom-width:1px; border-bottom-color:#06C"></textarea></td>
           <td align="right">Descuento %:</td>
           <td><Input type="text" name="descuento" size="5"  maxlength="5" style="border-bottom-style: groove; border-bottom-width: 1px; border-bottom-color:#06C"></td>
         </tr>
         <tr>
           <td align="right">&nbsp;</td>
           <td>&nbsp;</td>
           <td><input type="submit" name="save" id="guardar" value="Guardar" class="button1" onClick="return validardato(this.cod.value,this.marca.value,this.modelo.value,this.tipo.value,this.oferta.value,this.fecha.value,this.desc.value,this.descuento.value, this.img.value); this.form.action='save.php">
            <input type="submit" name="query" id="consultar" value="Consultar" class="button1">
               <input type="reset" name="clean" id="clean" value="Limpiar" class="button1">
           </td>
         </tr>
       </table>
<hr/>
</form>

entonces como hago para que cada boton valla y valide y luego siga enviando la informacion a la pagina correspondiente

Shell Root:
Pues no se como tendrás esas validaciones, es decir, en conjunto o independiente. En caso de hacerla en conjuntos, podrías hacer algo como esto...
Código
<form action = "#" method = "POST" onSubmit="return validarGeneral(this);">

Al estilo :http://www.ribosomatic.com/articulos/validando-formulario-con-jquery/

Zeroql:
Shell Root grax pero eso solo me sirve si es un solo boton.

modifique mi mensaje con el form completo para que sea mejor comprendido!!!

cassiani:
llamas desde tu función de validación al submit, algo así:

Código:

document.forms["myform"].submit();
document.myform.submit();


el problema con validar desde el cliente es que te lo puedes saltar no más deshabilitando el javascript, no olvides las validaciones del lado del servidor.

Shell Root:
Cita de: Zeroql en 14 Junio 2011, 19:37 pm

Shell Root grax pero eso solo me sirve si es un solo boton.

Para que veas que no, si usas tú lógica puedes implementarlo fácilmente con 2, 3, 4, 5, etc...  :silbar:

Navegación

[0] Índice de Mensajes

[#] Página Siguiente