Validate VF page required Fields Using JavaScript


Output:
                           
         

Code:
   <apex:includeScript value="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js" />
   <apex:includeScript value="https://ajax.microsoft.com/ajax/jquery.validate/1.6/jquery.validate.min.js"/>
  
 <head>
   <style type="text/css">
   .error {
       border-color: #E51400;
       background-color: #FFF0EF;
   }
   </style>
  </head>

  <body>
       <apex:form id="CustomerForm">
           <label for="customerName">Name &nbsp;</label>
               <apex:inputField value="{!caseVar.SuppliedName}"   html-placeHolder="Customer Name" id="customerName" /> <br></br>
               <apex:commandButton onclick="saveRec()"   value="SUBMIT" id="submit"  />
        </apex:form>
        <script type="text/javascript">
             $('[id$=CustomerForm]').validate();          
             errorclass: "myerrorclass";
         
            $('[id$=customerName]').rules("add",{
                required: true,
                minlength: 2,
                maxlength: 50,            
                messages:{
                    required:"",
                    minlength: jQuery.validator.format("")
                }                        
            });
        </script>
     
    </body>


Comments

Popular posts from this blog

Embed Special Characters in VF Page

Error: Compile Error: Illegal conversion from String to System.PageReference

Some Common Errors in the Visual flow