Bid
Bid

Reputation: 21

How to get the value of file upload in textbox?

I am working on a website and stuck in the following code. Here I have to get the value of file upload in textbox. I am using jquery code as follows,

$(document).ready(function() {
    $('input[name="product_picture"]').change(function() {
        var selectedValue = $(this).val();
        $('input[name="product"]').val(selectedValue);
    });
});

and my textbox and fileupload is,

<input type="file" name="product_picture" value="" />
<input type="text" name="product" />

But the textbox value is showing with full path like C:\fakepath\2.png, But I need to get only 2.png please help me out.

Upvotes: 2

Views: 2862

Answers (1)

OptimusCrime
OptimusCrime

Reputation: 14863

var fvals = $(this).val().split('\\');
$('input[name="product"]').val(fvals[fvals.length-1]);

Upvotes: 2

Related Questions