dido dido - 7 months ago 34
jQuery Question

Get filename from input [type='file'] using jQuery

This is the uploaded form.

<form class="alert alert-info">
<b id = "select_file" class="span3" style="font-weight: bold; cursor: pointer; ">Please select image</b>
<input class="span3" type="file" name="image_file" id="image_file" style="display:none " />
<input disabled="true" type="button" value="Upload image" class="btn" />

I use the following script to open a window with files. I want to show a file name in
<b id = 'select_file'>

How can I do this?

var _this = $(this);

var filename = $('#image_file').val();

$('.btn').attr('disabled', false);

Jai Jai

You have to do this on the change event of the input type file this way:

$('#select_file').click(function() {
    $('.btn').prop('disabled', false);
    $('#image_file').change(function() {
        var filename = $('#image_file').val();