0

Hello I have the following code that allows the user to select a file and upload it to the server:

 <form action="postphp.php" method="post" enctype="multipart/form-data">

         <input id="videoage" type="file" name="video" style="margin-left:-242px;margin-top:10px;opacity:0;">
         <label for="videoage" id="labelvideo">Choose Video...</label>
 </form>

It works great but when the user selects a file I want the 'choose video...' text on the input to change to 'example.mp4'. Is this possible using javascript if so how can I do that? Thanks.

1
  • You need to provide more code. Commented Oct 14, 2016 at 15:29

1 Answer 1

1

You can write in your script:

 jQuery(function($) {
  $('input[type="file"]').change(function() {
    if ($(this).val()) {
      var filename = $(this).val().split('\\').pop();
      $(this).closest('.file-choose').find('.file-name').html(filename);
    }
  });
});

where file-choose and file_name are the classes added in your <form> and <label> respectively.
Please check the snippet here.

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.