-1

I am trying to prevent IE from sending the full file path to the server on a file upload. So I am trying to parse out the filename. In my HTML I have:

<input id="fileupload" type="file" name="cutsheet" data-url="ws/cutsheet/representation">

So if the value attribute is "c:\folder\file.txt", I want to change that to "file.txt". I have the following javascript:

$('#fileupload').change(function() {
    var index = this.value.lastIndexOf('\\');
    this.value = this.value.substring(index + 1);
    alert(this.value);
});

However, my alert shows "c:\folder\file.txt". Can I not set the value attribute's value?

Jere
  • 1,196
  • 1
  • 9
  • 31
badgerduke
  • 1,013
  • 5
  • 16
  • 28

1 Answers1

0

Try split()

$('#fileupload').change(function(e) {
   var input = $(this).val();
   var pieces = input.split('\\');
   alert(pieces[pieces.length-1]);
});

Fiddle : http://jsfiddle.net/V5Qd8/

couzzi
  • 6,316
  • 3
  • 24
  • 40