When uploading, the filename turns the title

1

Colleagues.

Is it possible for the user to upload a file, the file name to turn the page title? For example:

The user will fill out a form where the first field is the file upload and the second field is an input text. When he selects the file by uploading "materia_matematica.pdf", automatically fill in the input text "Mathematical Matter".

Is this possible?

    
asked by anonymous 23.01.2017 / 17:17

2 answers

1

You can do this:

$('#file').on('change', function() {
  var f_name = $(this)[0].files[0].name;
  $('#name_file').val(f_name);
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script><inputtype="file" id="file">
<input type="text" id="name_file">

And to change the page title dynamically you can do:

$('#file').on('change', function() {
  var f_name = $(this)[0].files[0].name;;
  document.title = f_name;
});
    
23.01.2017 / 17:26
2

With javascript:

<html>
    <head>    
    </head>
    <body>
        <input id="arquivo" type="file" >

    <script>
        document.getElementById("arquivo").onchange = function(){
            var name = this.value.replace(/.*[\/\]/, ''); // limpar nome para chrome
             document.title = name.split(".")[0];
        };
    </script>
    </body>
</html>
    
23.01.2017 / 17:37