Reputation: 2463
How do I get upload file name after click the submit button. Below in the file upload field.
<input class="required-field" type="file" value="" name="cover_image">
I've tried with below but it not get the value.
var filename = $("[name='cover_image']", form).val();
Here I don't have ID fro the input filed but is it possible to get upload file name?
Upvotes: 2
Views: 1426
Reputation: 74738
Try this instead:
var filename = $("[name='cover_image']", 'form').val();
or one suggestion is to use form's id here:
var filename = $("[name='cover_image']", "formID").val();
or you can try this too:
var form = $('YourForm');
var filename = form.find("[name='cover_image']").val();
you can use form
because this is the jQuery object and you can find the specific element in it.
Upvotes: 1
Reputation: 82231
You will get the full path using .val()
for getting filename you can use:
$('[name="cover_image"].required-field').val().split('\\').pop();
Upvotes: 1