jquery - javascript read file object unknown id -
is possible use javascript file api read file object of unknown id?
i use custom file upload form in code doesn't have input element. uses plupload.js api , can't determine how access contents of file object.
for example if code had line 1, access contents of file object using code of line 2
input type="file" id="data"
var finput = document.getelementbyid("data"); var f = finput.files[0];
i tried document.files[0]
doesn't work. know similar?
instead of document.files[0]
, try document.queryselectorall('input[type="file"]')[0]
.
function demo(){ var inpts=document.queryselectorall('input[type="file"]'); alert(inpts[0].classname); }
<input type="file" class="file_input_a"><br> <input type="file" class="file_input_b"><br> <input type="file" class="file_input_b"><br> <button onclick="demo()">demo</button>
the above example echo's classname of file-input 0 (to show have reference it).
here on want grab (for example) first file (from first found input-element):
var f = inpts[0].files[0];
ps: there lot of related info in answer linked here.
Comments
Post a Comment