How would I check all the input fields in a form (check box, text and radio) to see if they are empty. Then highlight the empty ones with a red border. Thanks.
            Asked
            
        
        
            Active
            
        
            Viewed 56 times
        
    -1
            
            
        - 
                    Possible duplicate of [Check if inputs are empty using jQuery](http://stackoverflow.com/questions/1854556/check-if-inputs-are-empty-using-jquery) – Stephen P May 21 '16 at 00:23
1 Answers
0
            
            
        If you are using jQuery you could do something like this:
(function($) {
// After check for form submission
$('form :input').each(function(i) {
    if( $(this).val() == '' ) {
        // Just remove the closest() method if you want to give the 
        // actual input a border
        $(this).closest('.parent-div').css({ 'border': '1px solid #c20000' });
    }
});
})(jQuery);
 
    
    
        David
        
- 2,365
- 8
- 34
- 59
