<INPUT TYPE = "FILE"> tag

liunx

Guest
I'm stumped. I am trying to figure out how to place a default value inside of this tag. I tried all attributes for the file type tag and none of them work.<br />
<br />
I assumed that if I have the following tag:<br />
<br />
<INPUT TYPE = "FILE" VALUE="valuegoeshere><br />
<br />
Then there will be a default value of 'valuegoeshere' so I won't have to always select the browse button.<br />
<br />
Am I doing something wrong?<!--content-->hmmmn, interesting. I also cannot 'insert' a value into the field. Makes me think that it is a browser secutity setting... especially since you don't have the right to browse the users pc. <br />
<br />
I can validate the field though....<br />
<br />
<br />
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"><br />
<br />
<html><br />
<head><br />
<title>Untitled</title><br />
<script langauge=javascript><br />
function check(){<br />
if (document.form1.file.value==''){<br />
alert('empty!');<br />
}else{<br />
alert('full');<br />
}<br />
}<br />
</script><br />
</head><br />
<br />
<body><br />
<form name=form1><br />
<input type=file name=file>&nbsp;<input type=button value=Submit onClick="check()"><br />
</form><br />
<br />
<br />
</body><br />
</html><!--content-->It's a security thing - otherwise sneaky *******s would populate it with a nasty file name.<br />
According to MSDN, the value property is read-only.<br />
<!-- m --><a class="postlink" href="http://msdn.microsoft.com/workshop/author/dhtml/reference/properties/value_6.asp">http://msdn.microsoft.com/workshop/auth ... alue_6.asp</a><!-- m --><!--content-->Originally posted by ecojohnson <br />
I'm stumped. I am trying to figure out how to place a default value inside of this tag. I tried all attributes for the file type tag and none of them work.<br />
<br />
I assumed that if I have the following tag:<br />
<br />
<INPUT TYPE = "FILE" VALUE="valuegoeshere><br />
<br />
Then there will be a default value of 'valuegoeshere' so I won't have to always select the browse button.<br />
<br />
Am I doing something wrong? <br />
how would you know what the value is if you don't click on browse??<br />
<br />
just curious<!--content-->As has already been stated. It is read only. If it was not then a<br />
site could steal files from a users computer. The best you can<br />
do is suggest what the user should put in, and then filter the entry.<br />
<br />
That is why I use filtering like this:<br />
<br />
<head><br />
<title> file type filter </title><br />
<style><br />
body {background-color:blue;color:lightyellow}<br />
h1 {background-color:lightsalmon;color:seashell}<br />
#prompt {padding:10;background-color:blueviolet;color:floralwhite;<br />
width:250}<br />
.container {width:250;background-color:brown;color:peru;<br />
border:3px outset burlywood}<br />
.file {background-color:deepskyblue;colorcadet:blue;<br />
border-color:lightsteelblue}<br />
.sbutton {background-color:dimgray;color:pink;border-color:dodgerblue}<br />
</style><br />
<br />
<br />
<script language="JavaScript"><br />
<!-- <br />
var fileType = new Array(".gif", ".jpg", ".png");<br />
var arrayList="File Types: ";<br />
for (i=0;i<fileType.length;i++)<br />
{ arrayList+=fileType+" "; }<br />
var uploadOK=false;<br />
function filterFiles(thesource,thefile) <br />
{<br />
uploadOK = false;<br />
if (thefile)<br />
{<br />
while (thefile.indexOf("\\") != -1)<br />
{<br />
thefile = thefile.slice(thefile.indexOf("\\") + 1);<br />
}<br />
ftype = thefile.slice(thefile.indexOf(".")).toLowerCase();<br />
for (i=0;i<fileType.length;i++) <br />
{<br />
if (fileType==ftype)<br />
{ <br />
uploadOK=true;<br />
}<br />
}<br />
}<br />
if (uploadOK) <br />
{<br />
thesource.submit();<br />
alert('submitted');<br />
}<br />
else<br />
{<br />
alert(arrayList+' only please'); <br />
}<br />
}<br />
// End --><br />
</script><br />
</head><br />
<body><br />
<h1 align="center"> File Upload Filter</h1><br />
<p> With this script you can set the file extensions that are acceptable<br />
for uploading and the user will be prompted with the list. When<br />
they select a file and submit, the extention will be validated and <br />
either the submit will be executed for the user will get an alert.<br />
</p><br />
<br><br><br />
<div align="center"><br />
<script language="JavaScript"><br />
<!--<br />
document.write('<div align="center" id="prompt"> Upload '+arrayList+ '</div>');<br />
// --><br />
</script><br />
<div align="center" class="container"><br />
<form method="post" name="myform"><br />
<input type="file" name="myfile" class="file"><br />
<br><br><br />
<input type="button" name="Submit" value="Submit" class="sbutton"<br />
onFocus="this.blur()" <br />
onClick="filterFiles(document.myform,document.myform.myfile.value);return false"><br />
</form><br />
</div><br />
</div><br />
</body><br />
</html><!--content-->
 
Back
Top