Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Dec 2006
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    How do I verify the fields are filled in before the form action

    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <title>Untitled Document</title>
    <SCRIPT LANGUAGE="JavaScript">
    function verify() {
    var themessage = "You are required to complete at least these following fields: ";
    if (document.form.first_name.value=="") {
    themessage = themessage + " - First Name";
    }
    if (document.form.last_name.value=="") {
    themessage = themessage + " -  Last Name";
    }
    if (document.form.email.value=="") {
    themessage = themessage + " -  E-mail";
    }
    //alert if fields are empty and cancel form submit
    if (themessage == "You are required to complete at least these following fields: ") {
    document.form.submit();
    }
    else {
    alert(themessage);
    return false;
       }
    }
    //  End -->
    </SCRIPT>
    </head>
    
    <body>
    
    
    
    <form name=form method="post" action="http://www.s.com/servlet/servlet.WebToLead?encoding=UTF-8" onSubmit="return validateForm(this.submit)">
    <input type=hidden name="oid" value="00D300000000YKF">
    <input type=hidden name="retURL" value="http://www.s.com/thanks.html">
    
    
      <table width="100%" border="0">
        <tr>
          <td width="21%"><font face="Arial, Helvetica, sans-serif">
            
          <label for="first_name">First Name:</label>
          </font></td>
          <td width="79%"><font face="Arial, Helvetica, sans-serif">
            <input  maxlength="40" type="text" id="first_name" size="40" name="first_name">
            <label for="label3"></label>
          </font><font face="Arial, Helvetica, sans-serif">
          <label for="label4"></label>
          <label for="label5"></label>
          </font></td>
        </tr>
        <tr>
          <td><font face="Arial, Helvetica, sans-serif">
            <label for="last_name">Last Name:</label>
           
          </font></td>
          <td><font face="Arial, Helvetica, sans-serif">
            <input  maxlength="40" type="text" id="last_name" size="40" name="last_name">
          </font></td>
        </tr>
        <tr>
          <td height="24"><font face="Arial, Helvetica, sans-serif">
            <label for="label3">Email:</label>
          </font></td>
          <td><font face="Arial, Helvetica, sans-serif">
            <input  maxlength="80" type="text" id="email" size="60" name="email" />
          </font></td>
        </tr>
      </table>
      <p><br>
        <input type="submit"  name="submit" onclick="verify()">
    </form>
    </body>
    </html>
    The script is working correctly and coming up with a warning that these fields need to be filled but I cannot prevent it from sending the form regardless because of the action. I know I am missing something overly stupid here but I am sorta new making scripts. Anyone spare a moment and correct me where I need correcting?

  • #2
    Senior Coder
    Join Date
    Nov 2006
    Posts
    1,000
    Thanks
    0
    Thanked 0 Times in 0 Posts
    First of all you don't need the onclick for the submit button

    <input type="submit" name="submit" onclick="verify()">

    to

    <input type="submit" name="submit" />

    Second you need to call the right function in your form onsubmit

    <form name=form method="post" action="http://www.s.com/servlet/servlet.WebToLead?encoding=UTF-8" onSubmit="return validateForm(this.submit)">

    to

    <form name=form method="post" action="http://www.s.com/servlet/servlet.WebToLead?encoding=UTF-8" onSubmit="return veryify()">

    That should get you further.

    david_kw

  • #3
    Senior Coder
    Join Date
    Nov 2006
    Posts
    1,000
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Also you should be able to turn

    document.form.submit();

    in to

    return(true);

    david_kw


  •  

    Posting Permissions

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