I'm working in a Rails application and I want to conditionally apply a file upload field based on the existence of a previous input.
In this case if a user tries to upload a PDF file another file field presents itself to upload a placeholder image.
I'm a relative newb with jQuery and thus I have the following that will notice a change affect on the input field.
$("input[type=file]").on('change', function(){
{alert(this.files[0].name);
}
})
What I'm struggling with is how to have jQuery parse out and look for pdf files. I'm pretty sure I can figure out appending if PDF present with the form. How do I check the file upload for a specific file type of PDF?
I've also gone so far with:
$("input[type=file]").on('change', function(){
var fileExtension = 'pdf';
if ($.contains($(this).val().split('.'), fileExtension) > 0){
alert('Huzzah');
}
})
This does nothing. I get no errors but there's no alert when used in the console.