How to fetch File Field's file name into textbox using Rails and Prototype
I need to know how to fetch file field's file name into textbox using Rails and Prototype
I need to upload any file using
<%=file_field "text"%>
Then I need to fetc开发者_C百科h those file name into new textbox below
File fields are sandboxed in all modern browsers, so there are lots of things you can't do, such as setting their value. You can get the value, but you'll only get the name of the file, not the full path to the file.
Here's how you can do this with prototype, though.
<script type="text/javascript" charset="utf-8">
Event.observe(window, "load", function(){
$$("button")[0].observe("click", function(){
$$("input[type=text]")[0].value = $$("input[type=file]")[0].value
})
})
</script>
<input type="file" />
<input type="text" />
<button>Test</button>
Here's the results I get on various browsers on my mac:
- Opera: c:\fake_path[filename here]
- Safari: [filename here]
- Firefox: [filename here]
精彩评论