Results 1 to 2 of 2

Thread: Javascript validate form popup

  1. #1
    Join Date
    May 2008
    Posts
    5

    Default Javascript validate form popup

    Hey!

    I have a good javascript to validate your form and get a popup.

    I have tried it and it works with formail and HTML-template etc.

    Here is a sample code for validate e-mail field:

    PUT THIS IN HEAD:

    Code:
    <script type="text/javascript">
    function validate_email(field,alerttxt)
    {
    with (field)
    {
    apos=value.indexOf("@");
    dotpos=value.lastIndexOf(".");
    if (apos<1||dotpos-apos<2) 
      {alert(alerttxt);return false;}
    else {return true;}
    }
    }function validate_form(thisform)
    {
    with (thisform)
    {
    if (validate_email(email,"Všnligen ange din mailadress korrekt!")==false)
      {email.focus();return false;}
    }
    }
    </script>
    LOOK AT THIS (added onsubmit):

    Code:
    <form method="post" action="http://www.yoursite.se/formmail.php" onsubmit="return validate_form(this);" name="NameOnForm">
    NOTE: I have added: onsubmit="return validate_form(this);"



    More info:
    http://www.w3schools.com/js/js_form_validation.asp


    Hope this helps!
    Last edited by Xeonz; 21-May-2008 at 01:42 AM. Reason: better title

  2. #2
    Join Date
    May 2008
    Posts
    5

    Default Re: Javascript validate form popup

    Have a little problem myself.

    Anyone who know how to edit the code if I have more than e-mail to validate?

    I have tried this:

    Code:
    <script type="text/javascript">
    function validate_email(field,alerttxt)
    {
    with (field)
    {
    apos=value.indexOf("@");
    dotpos=value.lastIndexOf(".");
    if (apos<1||dotpos-apos<2) 
      {alert(alerttxt);return false;}
    else {return true;}
    }
    }function validate_form(thisform)
    {
    with (thisform)
    {
    if (validate_email(email,"Všnligen ange din mailadress korrekt!")==false)
      {email.focus();return false;}
    }
    }
     
     
    function validate_required(field,alerttxt)
    {
    with (field)
    {
    if (value==null||value=="")
      {alert(alerttxt);return false;}
    else {return true}
    }
    }function validate_form(thisform)
    {
    with (thisform)
    {
    if (validate_required(telbostad,"Všnligen ange telefonnummer till din bostad.")==false)
      {telbostad.focus();return false;}
    }
    }
    </script>
    The problem is that when I have one field correct the submitbutton doesnt restart the validation process?!

    The form still only value one field..
    Last edited by Xeonz; 21-May-2008 at 02:38 AM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Javascript image reload for image verify
    By swaz in forum FormMail Subscription Support
    Replies: 4
    Last Post: 28-Aug-2006, 12:24 AM
  2. Form Popup field
    By jlhorowitz32 in forum FormMail Subscription Support
    Replies: 2
    Last Post: 05-Jan-2006, 09:19 PM
  3. Validate number of characters in a TextArea field
    By matty in forum FormMail Subscription Support
    Replies: 3
    Last Post: 13-Oct-2005, 11:03 AM
  4. Checkboxes in JavaScript in conjunction with Formmail
    By Lesjo in forum FormMail Subscription Support
    Replies: 4
    Last Post: 15-Dec-2004, 10:46 PM
  5. Javascript and formmail: drop down list
    By bwv in forum FormMail Subscription Support
    Replies: 4
    Last Post: 05-Nov-2004, 10:18 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •