Let's say for example I have this code:
<input type="file" id="file" name="">
<input class="uploadarea">
<span class="button">Browse</span>
Now I've setupped some css to change the default input file button's look, And now the question is, How do i change .uploadarea
's value depending on the value of #file
when I select a file?
I currently have this code but I don't know what to do next.
var x = document.getElementsByTagName('input');
inputfile = x[0];
textbox = x[1];
Let's say for example I have this code:
<input type="file" id="file" name="">
<input class="uploadarea">
<span class="button">Browse</span>
Now I've setupped some css to change the default input file button's look, And now the question is, How do i change .uploadarea
's value depending on the value of #file
when I select a file?
I currently have this code but I don't know what to do next.
var x = document.getElementsByTagName('input');
inputfile = x[0];
textbox = x[1];
Share
Improve this question
asked Feb 16, 2012 at 13:18
Jürgen PaulJürgen Paul
15k28 gold badges96 silver badges136 bronze badges
6
- 1 What exactly do you want to do? – gdoron Commented Feb 16, 2012 at 13:22
-
I want to use the filepath in the
input[type=file]
as the value of the input with a classuploadarea
. – Jürgen Paul Commented Feb 16, 2012 at 13:27 - @user1099531 You can't get the path of a file with the file input element, just the filename. – Niklas Commented Feb 16, 2012 at 13:30
- 1 Why are you using a class ? are there lots of these ? – Manse Commented Feb 16, 2012 at 13:31
- ^nope, But some elements have the same styling as those ones. – Jürgen Paul Commented Feb 16, 2012 at 13:36
3 Answers
Reset to default 4Add an onchange
handler to handle the change
event on the file event :
<input type="file" id="file" name="" onchange="something(this.value)">
<input id="somethinghere" class="uploadarea">
<span class="button">Browse</span>
function something(val) {
document.getElementById('somethinghere').value = val;
}
You need to add the id
attribute for this to work
Yes. Use onchange
.
And by the way read alternate to onchange event in <input type='file' />. There are some problems with JS manipulation after file select.
Simple jQuery code:
$('#file').change(function(){
$('.uploadarea').val(this.value);
});
pure Javascript:
<input type="file" id="file" onchange="foo()" />
<input class="uploadarea" id="other" />
function foo(){
document.getElementById('other').value = this.value
}
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1742365470a4430199.html
评论列表(0条)