0

Resolved: The fixed Fiddle thanks to @Abdallah Arffak

I would like to remove the ../../../ from a chosen file to upload and instead simply show the file name such as index.html or whatnot.

JSFiddle: http://jsfiddle.net/5u5ovxdL/

HTML

<div id="file">Chose file</div>
<input type="file" name="file" />

JQuery

var wrapper = $('<div/>').css({height:0,width:0,'overflow':'hidden'});
var fileInput = $(':file').wrap(wrapper);

fileInput.change(function(){
    $this = $(this);
    $('#file').text($this.val());
})

$('#file').click(function(){
    fileInput.click();
}).show();
2
  • possible duplicate of Need a basename function in Javascript Commented Jan 15, 2015 at 15:15
  • I want to trail back to the '/' does that other question not simply remove the up to the '.'? Commented Jan 15, 2015 at 15:20

1 Answer 1

1

Try this :

fileInput.change(function(){
    $this = $(this);
    var file = $this.val().split("\\");
    if(file.length)
      $('#file').text(file[file.length-1]);
})
Sign up to request clarification or add additional context in comments.

2 Comments

Just updated my Fiddle however it doesn't seem to do the job.
i update my code, you have to use this split("\\") instead of split("/");

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.