By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,709 Members | 2,155 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,709 IT Pros & Developers. It's quick & easy.

how to take value of input element file in javascrript

P: 28
Hi,
I wish to know how to take value of input element file (<input type=file>) in javascript

Thanks in advance
Jan 18 '08 #1
Share this Question
Share on Google+
5 Replies


gits
Expert Mod 5K+
P: 5,327
hi ...

you could get it the same way as for all other 'input-types' ... assuming your node has an id="my_file" for example you could use:

Expand|Select|Wrap|Line Numbers
  1. var val = document.getElementById('my_file').value;
kind regards
Jan 18 '08 #2

P: 28
sorry.
When we using this method got 'null' value
Jan 18 '08 #3

gits
Expert Mod 5K+
P: 5,327
nope ... the following example works:

[HTML]<html>
<script type="text/javascript">
function get_file_path(id) {
var val = document.getElementById(id).value;
return val;
}
</script>
<body>
<input type="file" id="my_file"/>
<input type="button" onclick="alert(get_file_path('my_file'));" value="get file path"/>
</body>
</html>
[/HTML]
show the code you are using ... there must be another problem.

kind regards
Jan 18 '08 #4

P: 28
Thanks a lot

This code is working properly. I wish to know one more thing - how to give intial value to file input type(<input type=file>). I gave
Expand|Select|Wrap|Line Numbers
  1.  <input type="file" id="my_file"/> (In HTML page) 
  2. document.getElementById('my_file').value=="test.php"(In javascript)
  3.  
Above statement didn't assign value to "my-file".
Jan 19 '08 #5

acoder
Expert Mod 15k+
P: 16,027
I wish to know one more thing - how to give intial value to file input type(<input type=file>).
See this link. This is not supported by most browsers.
Jan 21 '08 #6

Post your reply

Sign in to post your reply or Sign up for a free account.