Using Javascript to Validate Fields in a Smart Capture Form

From $1

    Doc-Wiki-BannerHK.png

    (Click the banner to go to the related Docs.Code.ExactTarget.com page.)

    This document contains conceptual and procedural information about using JavaScript to validate fields in a Smart Capture form.

    What is Using JavaScript to Validate Fields in a Smart Capture Form

    You can use Javascript to validate fields and ensure subscribers enter information into the required fields. This JavaScript helps ensure that the information entered in the fields meet the requirements of the field to which that information will be saved.

    Why Use JavaScript to Validate Fields in a Smart Capture Form

    By using JavaScript, you can ensure that you get correct and valid information entered into your Smart Capture form. The form rejects incorrect or incorrectly formatted information and allows only valid entries.

    How to Use JavaScript to Validate Fields in a Smart Capture Form

    Insert the code in the HTML window of the content editor in order to include this functionality of your page. The screen and sample code shown below shows the JavaScript used to validate the subscriber's first name, last name, and email address. If any of these fields are left blank, the JavaScript prompts the user to enter the information before continuing.

     SC-JS.JPG

     

    <form name="myform" method="post" action="%%= RequestParameter('PAGEURL') =%%" onsubmit="return validate()"> 
           <script type="text/javascript"> 
           function validate() 
           { 
           var fname=document.getElementById("FirstName").value; 
           var lname=document.getElementById("LastName").value; 
           var femail=document.getElementById("Email").value; 
           submitOK="true"; 
           if (fname.length<1) 
           {  
           var Valert = "Please Enter your First Name \n"; 
           submitOK="false"; 
           }  
           else 
           { 
           var Valert = ""; 
           } 
           if (lname.length<1) 
           { 
           Valert = Valert + "Please Enter your Last Name \n"; 
           submitOK="false"; 
           } 
           if (femail.length<1) 
           { 
           Valert = Valert + "Please Enter your Email Address \n"; 
           submitOK="false"; 
           } 
           if (submitOK=="false") 
           { 
           alert(Valert); 
           return false; 
           } 
                  } 
           </script>

     

     


    This page was last updated by Ryan Williams on Tue, 31 Jan 2012 13:24:24 GMT.

    If you require assistance with the ExactTarget application, please contact Global Support. If you wish to send Ryan direct feedback, fill out the form below:

     


    Was This Page Helpful?
    Suggestions or Comments:
    Name (optional):
    Email Address (optional):
    Enter 7285 backwards:
       
    Tags: (Edit tags)
    • No tags
    FileSizeDateAttached by 
    SC-JS.JPG
    No description
    67.2 kB09:24, 31 Jan 2012AdminActions
    Comments (0)
    You must login to post a comment.

     
    Powered by MindTouch 2010
    Admin