Set Value on input element with type="file" and ask for change event

0

I have an input element with type="file", but I can not set the value to the element, I also want to fire the event change; this is the code:

let input_file=document.getElementsById('input');
input_file.setAttribute('value', "C:/images.jpg");
input_file.src= "C:/images.jpg";
let focus = new Event('focus', { bubbles: true });
input_file.dispatchEvent(focus);
let change = new Event('change', { bubbles: true });
input_file.dispatchEvent(change);

I also tried to set the value as:

input_file.value="C:/images.jpg";
    
asked by Paulo Sanchez 13.09.2018 в 23:01
source

1 answer

0

Good afternoon, for security reasons you can not set values to a file type field.

Good afternoon, for security reasons you can not set values to a file type field.

Imagine this:

<form name="foo" method="post" enctype="multipart/form-data">
    <input type="file" value="c:/passwords.txt">
</form>
<script>document.foo.submit();</script>

You do not want the websites you visit to do this, right?

    
answered by 14.09.2018 в 00:28