Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pre-Populate HTML form file input

Tags:

I have a VBScript that goes over an HTML form, fills it with fixed values and then submit it. It works fine so far, but now i need to set the location of a file that is going to be uploaded within the form data.

I believed if I set the location on the value it was going to work, but it doesn't.

 <input type='file' name="file_field" value='file_location'/> 

Also, I found this while researching. It says...

input type=file Value: Sets or retrieves the displayed value for the control object. This value is returned to the server when the control object is submitted.

Is there a way (by code) to fill that input, even with jQuery?

like image 313
Luigi Siri Avatar asked May 03 '13 18:05

Luigi Siri


People also ask

How do we pre populate a form input field with some text?

By typing it in. By giving the input tag a value attribute with whatever text you want pre-populated.

How do I change the input value of a file?

The only way to set the value of a file input is by the user to select a file. This is done for security reasons. Otherwise you would be able to create a JavaScript that automatically uploads a specific file from the client's computer.

How do you upload a form in HTML?

Create The HTML Form Some rules to follow for the HTML form above: Make sure that the form uses method="post" The form also needs the following attribute: enctype="multipart/form-data". It specifies which content-type to use when submitting the form.


1 Answers

No. This is not possible.

Browsers block against setting the value attribute on input of file type for security reasons so that you can't upload a file without the user's selected any file himself.

like image 141
Igor Popov Avatar answered Sep 21 '22 17:09

Igor Popov