admin管理员组文章数量:1429089
i have a form which has a file input element and when the user selects the file i want to set the selected file to another file input which is in hidden iframe,
this is what is my form:
<form name="uploadForm" >
<input type="file" id="fileone" name="fileone" value="" />
<button type="button" id="attachement_upload" onclick="addFile()" >Upload</button>
</form>
<iframe id="FileUploadFrame" name="FileUploadFrame" src="" style="display: none; border: 0; width: 0; height: 0;">
<form id="FileUploadForm" name="FileUploadForm" accept-charset="utf-8" target="FileUploadFrame" enctype="multipart/form-data" encoding="multipart/form-data" method="POST" action="CIMtrek_Regional_WhseForm_FileUpload">
<input type="file" id="filetwo" name="filetwo" value="" />
</form>
</iframe>
and my java script :
function addFile(){
//this is where i want to clone the fileone to filetwo and submit the form which is in iframe
}
I have seen some thing like this but really don't know how to do :
$(".inputfield1").change(function(){
var $this = $(this), $clone = $this.clone();
$this.after(clone).appendTo(hiddenform);
});
Please help me to get this done.
i have a form which has a file input element and when the user selects the file i want to set the selected file to another file input which is in hidden iframe,
this is what is my form:
<form name="uploadForm" >
<input type="file" id="fileone" name="fileone" value="" />
<button type="button" id="attachement_upload" onclick="addFile()" >Upload</button>
</form>
<iframe id="FileUploadFrame" name="FileUploadFrame" src="" style="display: none; border: 0; width: 0; height: 0;">
<form id="FileUploadForm" name="FileUploadForm" accept-charset="utf-8" target="FileUploadFrame" enctype="multipart/form-data" encoding="multipart/form-data" method="POST" action="CIMtrek_Regional_WhseForm_FileUpload">
<input type="file" id="filetwo" name="filetwo" value="" />
</form>
</iframe>
and my java script :
function addFile(){
//this is where i want to clone the fileone to filetwo and submit the form which is in iframe
}
I have seen some thing like this but really don't know how to do :
$(".inputfield1").change(function(){
var $this = $(this), $clone = $this.clone();
$this.after(clone).appendTo(hiddenform);
});
Please help me to get this done.
Share Improve this question asked Feb 8, 2013 at 12:47 Java QuestionsJava Questions 7,97343 gold badges119 silver badges177 bronze badges1 Answer
Reset to default 3You can't (or shouldn't) be able to do this. The file
input type, given that it has direct access to the user's file system, has special security restrictions. Most notably you cannot set the value
of a file
input in JavaScript, as this would allow you to do things like set it to something like ~/.ssh/id_rsa
and steal important data without the user being aware. As a consequence, jQuery shouldn't be able to clone the file
input because it can't set the value.
To get this to work you'll have to let the user click on the file
input that is in the iframe
, perhaps using some CSS positioning tricks to make it seem part of the page. Alternatively, if your users typically have more modern browsers, you could use the File API and upload the file with Ajax.
本文标签: javascripthow to clone a file input to another file input which is in hidden iframeStack Overflow
版权声明:本文标题:javascript - how to clone a file input to another file input which is in hidden iframe - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745523007a2661712.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论