Using input type = file

admin

Administrator
Staff member
Hi,<br />
I have just added a form to my page of input type "file" like so:<br />
<form><br />
<input type="file" name="fileSelector" /><br />
</form> <br />
<br />
What I want to know is how can I access the content of this input type's textfield? <br />
<br />
There is another buton on my page that when the user clicks on it should take the value from that the textfield and use it in some scripting methods. I have tried fileSelector.value but that doesn't seem to work. <br />
<br />
I have never used this input type before so I am a little confused. Does anyone know how I can take the filename the user has chosen from this form?<!--content-->What Dave said ... of course you can open it or change the page's location through:<br />
<br />
window.open(str)<br />
window.location = str;<br />
<br />
To run this, I would set up a function like the following:<br />
<br />
<form name="file"><br />
<input type="file" name="fileSelector"><BR><br />
<input type="button" value=" Open It! " onclick="dofile()"><br />
</form><br />
<br />
<script Language = "JavaScript"><br />
function dofile() {<br />
var str = document.file.fileSelector.value;<br />
// Remove the // from any of the following methods to allow it to work.<br />
// alert(str)<br />
// window.open(str)<br />
// window.location = str<br />
}<br />
</script><br />
<br />
Hope this works!<!--content-->
 
Back
Top