Validating array inputs using jquery validation plugin

 <script>  
 $(document).ready(function(){  
      //save complaint  
     $("#submitcomplaint").click(function(){  
      $("#fcomplaint").validate({  
           debug: false,  
         showErrors: function(errorMap, errorList) {  
           $(".errormsg").html($.map(errorList, function(el) {  
             return el.message;  
           }).join(", "));  
         },  
         wrapper: "span",  
           rules: {                 
                'complaintdesc[]': "required",                 
           },  
           messages: {                 
                'complaintdesc[]': "please enter complaint description",  
           },  
           submitHandler: function(form) {                 
                //$.post('updatecomplaint.php', $("#fcomplaint").serialize(), function(data) {                      
                //     alert(data.pesan);                                          
                //},"json");  
             alert('test save data :'+$("#fcomplaint").serialize());  
           }  
      });  
      });  
 });  
 </script>  
 <form name="fcomplaint" id="fcomplaint" method="post">  
     <div id="form-complaint">  
       <div class="errormsg"></div>  
       <hr />  
       <div id="form-complaint-sub">  
             <div>  
                 Complaint Type :   
             </div>  
             <div>  
               <select name="complaint_type[]">  
                 <option value="1">Hotel & Villa</option>  
                 <option value="2">Activity</option>  
               </select>  
             </div>  
             <div>  
                 Complaint Description :   
             </div>  
             <div>  
                 <textarea name="complaintdesc[]" cols="45" rows="4"></textarea>  
             </div>  
       </div>  
       <div id="form-complaint-sub">  
             <div>  
                 Complaint Type :   
             </div>  
             <div>  
               <select name="complaint_type[]">  
                 <option value="1">Hotel & Villa</option>  
                 <option value="2">Activity</option>  
               </select>  
             </div>  
             <div>  
                 Complaint Description :   
             </div>  
             <div>  
                 <textarea name="complaintdesc[]" cols="45" rows="4"></textarea>  
             </div>  
       </div>  
      </div>  
      <hr />   
      <div>  
         <input type="submit" name="submitcomplaint" id="submitcomplaint" value="Save">  
      </div>  
   </form>  

result :


Comments

Popular posts from this blog

VERIFIKASI SUARA MENGGUNAKAN METODE MFCC DAN DTW MENGGUNAKAN METODE MFCC DAN DTW (BAB II TINJAUAN PUSTAKA)

Data Flow Diagram (DFD)

Review Pemakaian Lenovo K900 Mati Total (Matot)