2

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.

edorian
  • 38,542
  • 15
  • 125
  • 143
Bid
  • 21
  • 1
  • 2
  • Similar question http://stackoverflow.com/questions/423376/how-to-get-file-name-from-full-path-using-javascript – coder Dec 12 '11 at 08:08

1 Answers1

2
var fvals = $(this).val().split('\\');
$('input[name="product"]').val(fvals[fvals.length-1]);
OptimusCrime
  • 14,662
  • 13
  • 58
  • 96