Ver Mensaje Individual
  #8 (permalink)  
Antiguo 03/02/2006, 13:29
Avatar de Dorita
Dorita
 
Fecha de Ingreso: junio-2005
Ubicación: Entre la silla y el escritorio
Mensajes: 97
Antigüedad: 18 años, 11 meses
Puntos: 0
Compañero Calavera:

haber, aclaremos algunas cosas:

esto es un formulario cierto? tu formulario tiene un nombre (pongámosle que se llama formulario1), y al momento de hacer el envío del formulario, los datos van a alguna parte, ya sea a la misma página u a otra. pongamos por ejemplo que al hacer el submit del formulario los datos van a una página que se llama otraPagina.html. entonces, en el script que va en el head de la página:

Código HTML:
<head>

<script>
function validar()
{
    var error = "Por favor, antes de buscar complete:\n\n";
    var a = ""

    if (form.buscar.value == "") { a += " La categoria y\n  los Datos a   buscar";}
    
     if (a != "") { alert(error + a); return false; }

     return true;

}
</script>  
</head> 
y en el body de tu página:

Código HTML:
<form name="formulario1" action="otraPagina.html" onSubmit=" return validar()">

<table width="650" border="0" cellpadding="0" cellspacing="0" bgcolor="">
    <!--DWLayoutTable-->
    <tr> 
      <td width="143" height="23"></td>
      <td colspan="8" valign="top"><hr></td>
      <td width="164">&nbsp;</td>
    </tr>
    <tr> 
      <td height="18"></td>
      <td width="55"></td>
      <td width="1"></td>
      <td width="189"></td>
      <td width="78"></td>
      <td width="47"></td>
      <td width="2"></td>
      <td width="3"></td>
      <td width="64"></td>
      <td></td>
    </tr>
    <tr> 
      <td height="8"></td>
      <td></td>
      <td></td>
      <td></td>
      <td colspan="3" rowspan="2" valign="top"> <select name="Equipos">
          <OPTION value="Tipo">Tipo </OPTION>
          <OPTION value="Marca">Marca </OPTION>
          <OPTION value="Modelo">Modelo </OPTION>
          <OPTION value="N_Serie">Nº de Serie </OPTION>
          <OPTION value="Fecha_Compra">Fecha de Compra </OPTION>
          <OPTION value="N_Factura">Nº de Factura </OPTION>
          <OPTION value="Rut_Proveedor">Rut del Proveedor </OPTION>
          <OPTION value="Rut_Asignado">Rut Asignado </OPTION>
        </SELECT ></td>
      <td></td>
      <td></td>
      <td></td>
    </tr>
    <tr> 
      <td height="12"></td>
      <td></td>
      <td colspan="2" valign="top"><strong>Elija la Categoria a Buscar:</strong></td>
      <td></td>
      <td></td>
      <td></td>
    </tr>
    <tr> 
      <td height="56"></td>
      <td></td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      <td></td>
      <td></td>
      <td></td>
      <td></td>
    </tr>
    <tr> 
      <td height="17"></td>
      <td></td>
      <td colspan="2" valign="top"><strong>Datos a Buscar:</strong> <br> </td>
      <td colspan="2" valign="top"><input type="text" name="buscar" size="25" ></td>
      <td></td>
      <td></td>
      <td></td>
      <td></td>
    </tr>
    <tr> 
      <td height="4"></td>
      <td></td>
      <td></td>
      <td></td>
      <td></td>
      <td></td>
      <td></td>
      <td></td>
      <td></td>
      <td></td>
    </tr>
    <tr> 
      <td height="1"></td>
      <td></td>
      <td></td>
      <td rowspan="2" valign="top"><input name="Submit" type="submit" value="Imp.Todos.Reg. "></td>
      <td></td>
      <td></td>
      <td></td>
      <td></td>
      <td></td>
      <td></td>
    </tr>
    <tr> 
      <td height="19"></td>
      <td></td>
      <td></td>
      <td></td>
      <td colspan="3" rowspan="2" valign="top"><input  type="button" name="submit" value="Buscar"></td>
      <td></td>
      <td></td>
    </tr>
    <tr> 
      <td height="1"></td>
      <td></td>
      <td></td>
      <td></td>
      <td></td>
      <td></td>
      <td></td>
    </tr>
    <tr> 
      <td height="21"></td>
      <td colspan="8" valign="top"><hr></td>
      <td></td>
    </tr>
    <tr> 
      <td height="93"></td>
      <td></td>
      <td></td>
      <td></td>
      <td></td>
      <td></td>
      <td></td>
      <td></td>
      <td></td>
      <td></td>
    </tr>
  </table>  

</form> 

lo que hace esto e slo siguiente: cuando hagas el envío del formulario, onSubmit llama al resultado de la funcion "valida()". si hay un error en el formulario, ademas de imprimir el mensaje de error que hiciste, va a devolver el valor false, lo que hace que el formulario no se envíe. si no hay problemas, pasa de largo los if y cuando encuentre un "return true", se envia el formulario.

si te quedan dudas, pregunta, no hay problema.
salu2.-
__________________

<nick>Dorita</nick>...si lo sé, soy una ñoña ;)