Buy Now
Sign in

Javascript validation

serie3 , July 19 2007, 23:38
S
serie3 8
July 19 2007, 23:38 #1315
This is the code in the "Form Javascript".

function validar_form_contactar()
{
  resp=true
  var printMain = ""
  if (document.Agitadors.client.value == "" )
  {
   resp=false;
    printMain = "Ha d'introduir un nom de client. \n";
  }
  if (document.Agitadors.direccio.value == "" )
  {
   resp=false;
    printMain = printMain + "Ha d'introduir una adreça. \n";
  }
  if (document.Agitadors.telefon.value == "" )
  {
   resp=false;
    printMain = printMain + "Ha d'introduir un telefon. \n";
  }
  if (document.Agitadors.mail.value == "")
  {
     printMain = printMain + "Ha d'introduir una direcció de correu. \n";
   resp=false;
    
     }else{
      invalidChars = " /:,;"
      for (i=0; i<invalidChars.length; i++)
      {
        badChar = invalidChars.charAt(i)
        if (document.Agitadors.mail.value.indexOf(badChar,0) != -1)
        {
         printMain = printMain +  "El e-mail introduit conté caracters invalids. \n";
          resp=false;
        }
      }
      atPos = document.Agitadors.mail.value.indexOf("@",1)
      if (atPos == -1)
      {
       printMain = printMain +  "El mail ha de contindre el caracter '@'. \n";
        resp=false;
      }
      else {
      if (document.Agitadors.mail.value.indexOf("@",atPos+1) != -1)
      {
          printMain = printMain +  "Ha d'introduir un e-mail correcte. \n";
        resp=false;
      }
      }  
      periodPos = document.Agitadors.mail.value.indexOf(".",atPos)
      if (periodPos == -1)
      {
       printMain = printMain +  "El e-mail ha de contenir almenys el caracter '.'. \n";
        resp=false;
      }
      if (periodPos+3 > document.Agitadors.mail.value.length)  
      {
       printMain = printMain +  "Ha d'introduir un e-mail vàlid. \n";
        resp=false;
      }
}
  if (resp==true)
  {  
    document.Agitadors.submit()      
  }
  else
  {
    alert(printMain);
  }
}

Now What I need write in the "Form tag attachment: something like onSubmit() " ??

And what I need write in the "<input type="submit" class="boton" value="Enviar" />"

Thanks for your help.
admin 28
July 20 2007, 03:32 #1319
Hi,

In the form tag attachment don't add anything, however edit your button code to be :
<input type="button" class="boton" value="Enviar" onClick="validar_form_contactar()" >


now at your code above, please replace every "Agitadors" with "ChronoContact_Agitadors"

Cheers

Max
Max
If your main question got answered then please mark the answer using the button!
Did you try the new ChronoForms7 ? if yes then please send us your comments!!
GreyHead 64
July 20 2007, 14:50 #1327
Hi serie3,

Max's fix should work fine with the form JavaScript that you already have. I'll put a more general post into the 'How To' section here.

Bob
ChronoForms technical support
If you'd like to buy me a coffee or two, thank you very much