admin管理员组文章数量:1415145
I don't even know if this is possible or not but is there a method you can take the value of the selected file in a input file field to a input text field?
Like this:
I don't even know if this is possible or not but is there a method you can take the value of the selected file in a input file field to a input text field?
Like this:
Share Improve this question asked Sep 13, 2010 at 20:10 MacMacMacMac 35.4k55 gold badges153 silver badges224 bronze badges3 Answers
Reset to default 5Hook on the change
event of the file field.
<form method="post" enctype="multipart/form-data">
<input type="file" onchange="this.form.filename.value = this.value">
<input type="text" name="filename">
</form>
Jsfiddle demo. Note that IE6/7 incorrectly gives the full path while other browsers correctly gives only the filename.
This should be possible by creating a new text input element and populating it with the .value
property of the file input.
Note, however, that all modern browsers store only the file name in the value
property for security reasons. You will not be able to get the full path of the selected file.
Sources: MSDN on IE8
You can't do it without first storing the file on your own server.
The file input control does not contain the file's data. Your browser provides it to you as a placeholder until you submit the file data via a POST form submission.
If you're after the file's path, you also cannot do that (in modern browsers, as Pekka says). The browser does not give that information to client-side scripts. It may provide the filename, however.
本文标签: javascriptInput File field to Input Text fieldStack Overflow
版权声明:本文标题:javascript - Input File field to Input Text field - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745203164a2647496.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论