-1

I have a button with the value 'Browser for files', when you select a file, the value should change to the file name. The text of the button doesn't change, it's still 'Browse for files' but it should change to the file name.

<input style="display: none" id="file-type" type="file" size="4" name="file"/>
<input id="browse-click" type="button" class="button2" value="Browse for files!"/>

script

$(window).load(function () {
    var intervalFunc = function () {
        $('#browse-click').html($('#file-type').val());
    };
    $('#browse-click').on('click', function () {
        $('#file-type').click();
        setInterval(intervalFunc, 1);
        return false;
    });
});

Fixed script:

$(window).load(function () {
    var intervalFunc = function () {
        $("#browse-click").prop('value', $('#file-type').val());
    };
    $('#browse-click').on('click', function () {
        $('#file-type').click();
        setInterval(intervalFunc, 1);
        return false;
    });
});
Ender Null
  • 19
  • 8

1 Answers1

0

I hope this helps:

$(window).load(function () {
    $('#file-type').change(function(){
        $('#browse-click').val($(this).val());
    });
    $('#browse-click').on('click', function () {
        $('#file-type').click();
    });
});
vher2
  • 980
  • 6
  • 9