Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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!

like image 222
Karim Avatar asked Apr 11 '09 13:04

Karim


People also ask

How do I get the value of text input field using jQuery?

To get the textbox value, you can use the jQuery val() function. For example, $('input:textbox'). val() – Get textbox value.

How do you show the value of an input type file?

The only way to set the value of a file input is by the user to select a file. This is done for security reasons. Otherwise you would be able to create a JavaScript that automatically uploads a specific file from the client's computer.

How can I get full path of uploaded file in HTML using jQuery?

var fullPath = $('#fileUpload1'). val();


1 Answers

You need to use val rather than value.

$("#fileinput").val(); 
like image 129
Will Avatar answered Sep 17 '22 16:09

Will