I would like to copy the value of a input:file to input:text. I can do it with plan JavaScript but I will like to know how to do it with jQuery.
----JavaScript
// This what the script would look like with plain JavaScript
// It works fine. I just woulld like to know who to do it with jQuery.
function fakeScript() {
var filepath;
filepath = document.adminForm.tumb.value;
filepath = filepath.substring(filepath.lastIndexOf('\\')+1, filepath.length);
document.adminForm.tumbFake.value = filepath;
}
I would like to copy the value of a input:file to input:text. I can do it with plan JavaScript but I will like to know how to do it with jQuery.
----JavaScript
// This what the script would look like with plain JavaScript
// It works fine. I just woulld like to know who to do it with jQuery.
function fakeScript() {
var filepath;
filepath = document.adminForm.tumb.value;
filepath = filepath.substring(filepath.lastIndexOf('\\')+1, filepath.length);
document.adminForm.tumbFake.value = filepath;
}
Share
Improve this question
asked Dec 5, 2009 at 21:31
SgtOJSgtOJ
5892 gold badges10 silver badges24 bronze badges
1
- This version too "plain" for ya is it? – Crescent Fresh Commented Dec 5, 2009 at 21:35
4 Answers
Reset to default 3If you have something that works in "plain Javascript", it'll work with jQuery too : jQUery is just a library, that adds functions -- it doesn't prevent anything from working (or there is some kind of bug in it ^^ )
var fileValue=$("input[type='file']").val();
var inputValue=$("input[type='text']").val(fileValue);
cheers
You probably cannot use the value attribute of a file input with JQuery.
"The value attribute cannot be used with <input type="file">.
" - http://www.w3schools./tags/att_input_value.asp
To get the text value of a file from an <input type="file"/>
element, use yourFileInputElement.files[0].getAsText("utf-8")
.