Is there a way to validate only specific fields within a div, rather than all fields? Take a look at this jsfiddle for an example. Once validation is passed, I want the div to be hidden. However, I do not want to include certain fields such as the input field that appears when 'Yes' is checked on the checkbox. Similarly, selecting 'NoGame' from the dropdownlist should exclude two fields in the lower div (green border) from the validation process. Any suggestions?
Below is the code that validates all fields and hides the div, as demonstrated in the fiddle.
function IsValid(divid) {
var $div = $('#' + divid);
var result = true;
$.each($div.find("input[type='text']"), function (i, input) {
if ($(input).val().length == 0 || $.trim($(input).val()) == '') {
result = false;
return;
}
});
return result;
}
$(document).ready(function(){
$("#hide").click(function(){
if (IsValid('contentone')) {
$('#contentone').hide();
};
});
});