We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

validation

Hi Team .
                                 How to validate drop down and textbox  in page load and  button click event

1 Reply

PO Prince Oliver Syncfusion Team November 1, 2016 09:53 AM UTC

Hi Rajivgandhi,   
  
Thanks for contacting Syncfusion Support.   
  
In order to validate dropdownlist using jQuery validation plugin, you need to set defaults for the validator. Refer to the following code snippet.   
  
$.validator.setDefaults({   
            ignore: [], // To include hidden input in validation   
            errorClass: 'e-validation-error'// To get the error message on jquery validation   
            errorPlacement: function (error, element) {    
                             $( element ).closest( "form" )   
                .find( "label[for='" + element.attr( "id" ) + "']" ).append( error );   
            } // To place the error message on required element   
        });   
  
  
Note: To include dropdownlist in validation, you have to clear the ignore in setDefaults because by default in jQuery validation the hidden inputs are ignored from validation and our dropdownlist has the input element hidden.   
  
Set the rules for validation.    
$("form[id='details']").validate({   
       rules: {   
              field: {   
                     required: true  // Rules for textbox   
              },   
              drpdwn: {   
                     required: true  // Rules for Dropdownlist   
              }   
       },   
});   
  
  
The Textbox and Dropdownlist will be validated on form submit. To validate on button click use form valid method.   
    
function onClick(){   
              $("form[id='details']").valid();   
}   
  


 
 
We have attached a Playground Sample for your reference.   
  
Regards,   
Prince  


Loader.
Live Chat Icon For mobile
Up arrow icon