0

I have a form element like this:

<form enctype="multipart/form-data" id="uploadform" method="post"  action="upload.php"      target="upload_target" onsubmit="startUpload();">
 <input id="file" name="file" type="file" class="target"/>

The user inputs a file-name - let's say it's "The Beatles - Revolution.mp3". Is there a way I can grab that from the input form element file after they select a file and display it in a DIV?

1
  • not from the input, because its value resets after submission. but you can either output it back in the php response in some hidden element or var and grab it from there Commented Dec 13, 2014 at 18:35

1 Answer 1

2

I hope I didn't misunderstand, but how about:

$("#songFile").on("change", function(e) {
   var s = $(this).val().split("\\");
   $("#result").text("You've selected - " + s[s.length - 1]);
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type="file" id="songFile" />
<div id="result"></div>

Sign up to request clarification or add additional context in comments.

Comments

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.