I have question about how to validate input type=text
or textbox OR input type="file"
upload a file at a time using javascript or jquery?
1) If textbox is selected than no need to upload file. 2) If upload file is selected than no need to textbox. 3) Both
simple with required
attribute
<form>
<input type="text" required="true">
<input type="file" required="true">
<button type="submit">validate</button>
</form>
Or with Javascript validation
Updated
$('button').click(function(){
var a =$(".validate").map(function(){
return $(this).val().trim() ? true : false
}).get()
if(a.includes(true)){
console.log('pass')
}
else{
console.log('select any one')
}
})
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type="text" class="validate">
<input type="file" class="validate">
<button>validate</button>
</div>
" Just check both file and text box is empty or not before proceeding further."
if(!$('input:text').val().trim() && !$('input:file').val().trim()){
alert('Enter required data');
}