locked
How can I set default file name of input file RRS feed

  • Question

  • User283528319 posted

    hi all,

    when user clicks the input file button I want to write 65847-68548654.pdf into its value to make it easy to chose right file among lots of others

    as far as I know, it wasn't allowed before 2017 because of security reasons but now it is possible.

    Could you tell me how can I do it?

    thanks

    Friday, July 19, 2019 6:56 AM

Answers

  • User-857013053 posted
    <script type="text/javascript">
        $(document).ready(function(){
            $('input[type="file"]').change(function(e){
                var fileName = e.target.files[0].name;
                alert('The file "' + fileName +  '" has been selected.');
            });
        });

    </script>

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, August 2, 2019 4:30 AM

All replies

  • User-821857111 posted

    it wasn't allowed before 2017 because of security reasons but now it is possible
    No, it's still not possible for the same reasons.

    Friday, July 19, 2019 7:03 AM
  • User-2054057000 posted

    You can achieve it by using custom attributes of input file button. It is not meant to store data but to allow the developer to assign some values to them to use it later in the code since HTML is stateless.

    I recommend you to read about them - https://www.w3schools.com/tags/att_global_data.asp

    Saturday, July 20, 2019 12:02 PM
  • User283528319 posted

    You can achieve it by using custom attributes of input file button. It is not meant to store data but to allow the developer to assign some values to them to use it later in the code since HTML is stateless.

    I recommend you to read about them - https://www.w3schools.com/tags/att_global_data.asp

    yeah there are lots of way to store data localy but I don't want to use them because of  security reasons therefore I chose sessions at first

    Saturday, July 20, 2019 12:10 PM
  • User-474980206 posted
    The data- attribute will not help with the file input, as the file name is can not be set by JavaScript.

    Sunday, July 21, 2019 5:43 PM
  • User-857013053 posted
    <script type="text/javascript">
        $(document).ready(function(){
            $('input[type="file"]').change(function(e){
                var fileName = e.target.files[0].name;
                alert('The file "' + fileName +  '" has been selected.');
            });
        });

    </script>

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, August 2, 2019 4:30 AM
  • User283528319 posted

    it gave me good ideas but didn't tried it yet

    Friday, August 2, 2019 6:51 AM
  • User-821857111 posted

    The answer that you marked as correct does not set the default file name of the input. All it does is tell you the name of the file that the user selected. 

    As I said right at the beginning, it is not possible to set a value for the file name in an input type-file. 

    Friday, August 2, 2019 8:32 AM
  • User283528319 posted

    The answer that you marked as correct does not set the default file name of the input. All it does is tell you the name of the file that the user selected. 

    As I said right at the beginning, it is not possible to set a value for the file name in an input type-file. 

    no problem, as I said it gave me good ideas

    Friday, August 2, 2019 12:15 PM