0

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; 
}
1
  • This version too "plain" for ya is it? Commented Dec 5, 2009 at 21:35

4 Answers 4

3

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 ^^ )

Sign up to request clarification or add additional context in comments.

Comments

2
var fileValue=$("input[type='file']").val();
var inputValue=$("input[type='text']").val(fileValue);

cheers

Comments

1

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

2 Comments

Yes, you are correct. I notice it a while back. However, thanks for your answer.
no problem. Please append the correct answer in your question so it will help other people in the future.
-2

To get the text value of a file from an <input type="file"/> element, use yourFileInputElement.files[0].getAsText("utf-8").

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.