Javascript – How to use jQuery to get the current value of a file input field

domjavascriptjquery

From what I've ready you should be able to use the 'value' property of a file input field to get the currently set path of that field. But when I do this:

 $('#fileinput').value()

I get 'undefined'. The ID of the field is set to "fileinput" I'm sure. Does anyone have any thoughts on why this might not be working for me?

And by the way, this works:

var d = document.getElementById('AttachmentFile');
alert(d.value);

So I guess this has something to do with the way jQuery works that I don't fully understand.

Thanks!

Best Answer

You need to use val rather than value.

$("#fileinput").val();