Turtle Turtle - 1 year ago 90
Javascript Question

Accessing value of javascript file input variable

I am trying to get the filepath of the selected file.
Using the debugger, I see that the file has an property called value which is equal to :


However when I try to access file.value, the filepath is equal to null.
I am using Java 8, Struts 1.2, Jsps, and Chrome

function validateFile(file)
filepath = file.value; /*This is null*/
return true;


<input type="file" id="theFile[0]" onChange="validateFile(this)"/>

Answer Source

I guess it wasn't too much work after all :)

function validateFile(file)
    filepath = file.value;
    document.getElementById('result').innerText = filepath;
    return true; 
<input type="file" onChange="validateFile(this)"/>
<div id="result">[result will be here]</div>

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download