Click to See Complete Forum and Search --> : setting the value of a "file" input


jrlaughlin
10-20-2003, 10:14 AM
Hello all,

I have a file input on my page that I need to clear the value of in response to a button click. But setting the value of it to "" does not work.

Here is what I have:



<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>test bed</title>
<script language="Javascript">


function clearIt(){
file = document.getElementById('filTest');
file.value = '';
alert(file.value);
}
</script>
</head>
<body>
<p>
<form name="ignoreThis">
<p>
<input type="file" id="filTest">
<br><input type="button" value="clear" onclick="clearIt();">
</p>
</form>
</p>
</form>
</body>
</html>




If you open the page in a browser and click the browse button to select a file then click clear, you would expect to get an alert box that says nothing. But it gives me the original value....and the value in the control does not change.

I have also tried setting the value to null and "", and "nothing". No change ever shows.


Anyone have any ideas?

Thanks.

James.

AdamGundry
10-20-2003, 10:47 AM
It's a security issue. Obviously what you want to do is ok, but JS does not allow you to set the value property (because you could theoretically create a hidden file upload component and upload one of the user's files to a remote server).

Adam

jrlaughlin
10-20-2003, 11:08 AM
Adam,

Yes, you are right. That could be pretty nasty couldn't it?

I guess I'll have to find another way to accomplish this.

Thanks.

James