Click to See Complete Forum and Search --> : Using input type = file


jovialjonny
06-09-2003, 05:39 PM
Hi,
I have just added a form to my page of input type "file" like so:
<form>
<input type="file" name="fileSelector" />
</form>

What I want to know is how can I access the content of this input type's textfield?

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.

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?

steelersfan88
07-05-2003, 11:08 AM
What Dave said ... of course you can open it or change the page's location through:

window.open(str)
window.location = str;

To run this, I would set up a function like the following:

<form name="file">
<input type="file" name="fileSelector"><BR>
<input type="button" value=" Open It! " onclick="dofile()">
</form>

<script Language = "JavaScript">
function dofile() {
var str = document.file.fileSelector.value;
// Remove the // from any of the following methods to allow it to work.
// alert(str)
// window.open(str)
// window.location = str
}
</script>

Hope this works!