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.
Unfortunately, activation email could not send to your email. Please try again.

validation

Thread ID:

Created:

Updated:

Platform:

Replies:

127169 Oct 31,2016 08:12 AM Nov 1,2016 05:53 AM JavaScript 1
loading
Tags: ejDropDownList
rajivgandhi
Asked On October 31, 2016 08:12 AM

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

Prince Oliver [Syncfusion]
Replied On November 1, 2016 05:53 AM

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  


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.

;