Reputation: 589
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;
}
Upvotes: 0
Views: 9757
Reputation: 4849
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.com/tags/att_input_value.asp
Upvotes: 1
Reputation: 1924
var fileValue=$("input[type='file']").val();
var inputValue=$("input[type='text']").val(fileValue);
cheers
Upvotes: 2
Reputation: 35850
To get the text value of a file from an <input type="file"/>
element, use yourFileInputElement.files[0].getAsText("utf-8")
.
Upvotes: -2
Reputation: 400972
If 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 ^^ )
Upvotes: 3