So if I understand this correctly, out of 40 text boxes 20 are mandatory and out of 5 uploads 1 is mandatory. If the text boxes and html inputs add a class say mandatory.
select all textboxes which are mandatory and loop through for text.
so say this is the tag:
<input type="text" class="mandatory" id="txtbx1" />
<input type="text" class="mandatory" id="txtbx2" />
<input type="text" class="mandatory" id="txtbx3" />
<input type="text" id="txtbx3" />
<input type="text" class="uploadTextBox" id="upTtx" /><input type="button" value="Upload" onclick="FillTextBox();" />
<input type="text" class="uploadTextBox" readonly="readonly" /><input type="button" value="Upload" onclick="FillTextBox();" />
<input type="text" class="uploadTextBox" readonly="readonly" /><input type="button" value="Upload" onclick="FillTextBox();" />
<input type="text" class="uploadTextBox" readonly="readonly" /><input type="button" value="Upload" onclick="FillTextBox();" />
<script>
function Validate() {
var areAllFieldsValidated = false;
var isAtleastOneUploadAvailable=false;
$('.mandatory').each(function () {
if ($(this).val() == '') {
areAllFieldsValidated = false;
$(this).css({ 'background-color': 'Red' });
}
else {
$(this).css({ 'background-color': 'White' });
areAllFieldsValidated = true;
}
});
$('.uploadTextBox').each(function () {
if ($(this).val() != '') {
isAtleastOneUploadAvailable = true;
}
});
if (areAllFieldsValidated && isAtleastOneUploadAvailable)
{ alert('we are good'); }
else if (!areAllFieldsValidated)
{ alert('Highlighted Fields missing') }
else if (!isAtleastOneUploadAvailable) {
$('.uploadTextBox').focus();
alert('Upload at least one file.');
}
}
</script>
This is on top of my head. Obviously it can be improved perhaps. You can also use some validation plugins to make life easier.
Hop this helps.