Tema: validar form
Ver Mensaje Individual
  #1 (permalink)  
Antiguo 24/11/2013, 11:31
helenp
 
Fecha de Ingreso: mayo-2009
Mensajes: 382
Antigüedad: 15 años, 8 meses
Puntos: 6
validar form

Hola, tengo para un formulario tres funciones,
uno onload, uno toogle y otro onsubmit:

Código Javascript:
Ver original
  1. <script type="text/javascript">
  2.  function onload() {
  3.                   document.getElementById("uno").style.display = "block";
  4.                   document.getElementById("dos").style.display = "none";
  5. document.getElementById("tres").style.display = "none";
  6.  }
  7.  
  8.             function toggle(elemento) {
  9.               if(elemento.value=="1") {
  10.                   document.getElementById("uno").style.display = "block";
  11.                   document.getElementById("dos").style.display = "none";
  12.                   document.getElementById("tres").style.display = "none";
  13.                }
  14.                else{
  15.                    if(elemento.value=="2"){
  16.                        document.getElementById("uno").style.display = "none";
  17.                        document.getElementById("dos").style.display = "block";
  18.                        document.getElementById("tres").style.display = "block";
  19.                    }
  20.                 }
  21.                  }
  22.                  
  23.     function OnSubmitForm()
  24. {
  25. if(document.choise.a[0].checked == true)
  26.  {
  27.  document.searcherform.action="http://www.mysite.com/searchtest.php?z=z&d=d&t=t&s=s&day=day&month=month&day2=day2&month2=month2&e=e"
  28.  }
  29.  else
  30.   if(document.choise.a[1].checked == true)
  31.  {
  32.  document.searcherformsales.action="http://www.mysite.com/sales/searchtest.php?z=z&t=t&b=b&p=p&p1=p1&enviar=enviar"
  33.  document.searcherformsales2.action="http://www.mysite.com/sales/searchtest.php?id=id&enviarid=enviarid"
  34.  }
  35.  return true;
  36.  }                           
  37.     </script>

Ahora necesito hacer una validación, y es en el document.searchform y en el primer choise,
este es el validador:
Código Javascript:
Ver original
  1. <script type="text/javascript">
  2. <!--
  3.  
  4. function validate_form ( )
  5. {
  6.     valid = true;
  7.  
  8.  
  9.         if ( ( document.searcherform.s[0].checked == false ) && ( document.searcherform.s[1].checked == false ) )
  10.         {
  11.                 alert ( "Please choose all dates or selected dates" );
  12.                 valid = false;
  13.         }
  14.  
  15.  
  16.         return valid;
  17. }
  18.  
  19. //-->
  20.  
  21. </script>

Creo que debe de ir anidadas ya que son dos formularios, quiero poner la funcion validate form dentro de esto ya que es en este formulario donde está:
Código Javascript:
Ver original
  1. function OnSubmitForm()
  2. {
  3. if(document.choise.a[0].checked == true)
  4.  {
  5.  document.searcherform.action="http://www.mysite.com/searchtest.php?z=z&d=d&t=t&s=s&day=day&month=month&day2=day2&month2=month2&e=e"
  6.  }

Última edición por helenp; 24/11/2013 a las 11:46