I have many of these input types:
<input type="file" name="file_upload">
And when the submit button is clicked, I want to check via JS if one these fields are not empty (in other words, there is at least one file is uploaded).
Here's my code which doesn't work:
$('#upload-button').live('click', function () {
var has_selected_file = $('input[type=file]').val();
if (has_selected_file) {
/* do something here */
}
else {
alert("No file selected");
}
});
This always alerts no file selected.