This question already has answers here:
How to set file input value when dropping file on page? [duplicate]
(1 answer)
How to set File objects and length property at FileList object where the files are also reflected at FormData object?
(1 answer)
Closed 6 years ago.
Is there a way to set the value of a file input (<input type="file" />) or is that all blocked for security? I'm trying to use google gears' openFiles to make a simple multi-uploader.
Note:
The answer(s) below reflect the state of legacy browsers in 2009. Now you can actually set the value of the file input element dynamically/programatically using JavaScript in 2017.
See the answer in this question for details as well as a demo:How to set file input value programatically (i.e.: when drag-dropping files)?
It is not possible to dynamically change the value of a file field, otherwise you could set it to "c:\yourfile" and steal files very easily.
However there are many solutions to a multi-upload system. I'm guessing that you're wanting to have a multi-select open dialog.
Perhaps have a look at http://www.plupload.com/ - it's a very flexible solution to multiple file uploads, and supports drop zones e.t.c.
I am working on an angular js app, andhavecome across a similar issue. What i did was display the image from the db, then created a button to remove or keep the current image. If the user decided to keep the current image, i changed the ng-submit attribute to another function whihc doesnt require image validation, and updated the record in the db without touching the original image path name. The remove image function also changed the ng-submit attribute value back to a function that submits the form and includes image validation and upload. Also a bit of javascript to slide the into view to upload a new image.
I ended up doing something like this for AngularJS in case someone stumbles across this question:
const imageElem = angular.element('#awardImg');
if (imageElem[0].files[0])
vm.award.imageElem = imageElem;
vm.award.image = imageElem[0].files[0];
And then:
if (vm.award.imageElem)
$('#awardImg').replaceWith(vm.award.imageElem);
delete vm.award.imageElem;
I had similar problem, then I tried writing this from JavaScript and it works! : referenceToYourInputFile.value = "" ;
Related
Is it possible somehow to open url, without loading it. Let me explain, I'm creating check-box which will let to create new log and automtically input values. I know how to take boxes and input value into them using javascript. But i don't know how to open that page without loading it on screen OR write that url that javascript would type values into that page.
The concept you should read up on is AJAX. It sounds like it would fit your needs: post our data to a script, let the script do it's job, and work with the answer (or completely ignore the answer)
Since it seems that you are a beginner, maybe you might want to take a look at the jQuery Ajax documentation.
This question already has answers here:
How to set file input value when dropping file on page? [duplicate]
(1 answer)
Dynamically set value of a file input [duplicate]
(4 answers)
How to set a value to a file input in HTML?
(10 answers)
Closed 9 years ago.
Note:
The answers & comments below reflect the state of legacy browsers in 2009. Now you can actually set the value of the file input element dynamically/programatically using JavaScript in 2017.
See the answer in this question for details as well as a demo:How to set file input value programatically (i.e.: when drag-dropping files)?
I have 2 input type="file"
<input type="file" id="attach_file_1" name="attach_file_1" />
<input type="file" id="attach_file_2" name="attach_file_2" />
after "choosing" file for attach_file_1, there is possible to set same value for attach_file_2 using javascript ?
I don't think you can. I believe it's a security issue. You can't set the value of a file input type. Otherwise you could hide the file input element and upload a file to your server without the user's knowledge.
One way of achieving the desired functionality is to add a flag in form and mark it true when you want to copy the file information to second input. Then, on the server, you can check for that flag and use the file from first input to do whatever you wish to do with the second input.
Given that you want another input with the same value, it does appear to be possible using .cloneNode(), at least in Firefox. So far, Chrome behaves differently.
http://jsbin.com/ohafom/2/
Also note that I haven't actually tested the upload. As far as I know, Firefox will only send one. Still interesting that the clone worked.
The only way I can figure out to achieve that (but works only to "pass" the file from one to another) is to dynamically switch the input field position and names so that the file looks like it have passed from one to another.
Otherwise, it's security issue, most browsers won't let you manipulate file inputs at all.
I'm trying to populate a link list in tinyMCE, but the values need to change depending on what the user has inputted in some other form fields. An array is already getting populated on the page that contains these value so wondered if it's possible to use this instead of populating with the external file like described here:
http://www.tinymce.com/wiki.php/Configuration:external_link_list_url
EDIT
So is there an alternative to 'external_link_list_url'. Say for example 'external_link_list_var'
tinyMCE.init({
...
external_link_list_url : "myexternallist.js"
});
i'd have
tinyMCE.init({
...
external_link_list_var : SomeVar
});
If not i guess one way to do it would be to pass the values via a query string to a php file.
You may restart the editor instance and set the external_link_list according to your needs.
For correctly shutting down tinymce have a look at some stackoverflow questions regarding tinymce.
I want to add multiple custom fields to the lightbox in dhtmlScheduler. I realize that this is a dup of a prior question but that answer is incomplete/incorrect.
My application correctly stores and recalls data from a MySQL database using dhtmlxDataProcessor on the client and dhtmlxConnector via PHP on the server side. I have carefully read, re-read, and parsed documentation on Custom "details" form. I've worked with the code in the 05_custom_editor.html sample.
The problem is that those examples do not work - they silently fail to store the second field, "Details", in the Description section. This is not surprising since nowhere is the field mapped to a database column.
What changes are needed so the "Details" field of the example form stored in the database and recalled with the event?
What changes are needed to support read-only data in the Details field that is populate based on the "Text" field? What I'm thinking of is a name that has an address associated with it.
How to invoke a custom windows with a form from the lightbox to populate the address?
I would prefer to be able to do this by extending the default lightbox, but that is not a requirement.
Any guidance is appreciated.
There are 3 required fields when using dhtmlScheduler. They are the first 3 in your PHP connector:
$scheduler->render_table("my_table","id","start_date,end_date,name,details,....
Your connector may use any column names as long as the order is preserved. But because it's required and used all over the place the dhtmlScheduler must refer to the name of the event. It is called "text".
The lightbox section maps description on to "text". I think that there is no
scheduler.locale.labels.section_description
for the same reason.
1) Update the PHP connector to pull in the required fields.
2) You can use sched.formSection('myfield') to get components from inside the lightbox, then you can add javascript to blur on focus.
3) Normal javascript
You can use one of the custom events alter any form items before you display the lightbox.
My dhtmlScheduler seems very vocal when it fails! What does the console say? Have you stepped through to see where it's failing?
This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
Dynamically set value of a file input
I have an input file HTML form and I want to set the initial value for the file path in an HTML form . I try to change tag "value" but it doesn't work anyway.
<input type="file" name="testcase" value= "C:\test.txt">
Please give me some advice for this small problem. Thanks.
From HTMLHelp.com :
The file input type creates a field
through which users can upload files
from their local computer or network.
The VALUE attribute specifies the name
of the initial file, but it is
typically ignored by browsers as a
security precaution.
Therefore, setting an initial value is not supported.