最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Copying INPUT FILE value to INPUT TEXT with click in jQuery - Stack Overflow

programmeradmin4浏览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; 
}

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
Add a ment  | 

4 Answers 4

Reset to default 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 ^^ )

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").

发布评论

评论列表(0)

  1. 暂无评论