0

I prefill file inputs value then append them to a div. When I try check for their value later on (onsubmit) their value returns empty even though inspecting the element there is a value set.

Visually the inputs show no value?

Please see snippet below for demonstration:

function addfile() {
  $('#fileupload').append('<input type="file" checkme="checkme" name="file[]" value="C:fakepath/hello.jpg" />');
}

function test() {
  $('input,textarea,select').filter('[checkme]:visible').each(function() {
    alert($(this).val());
  });
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="fileupload">
  <input type="text" checkme="checkme" value="hello" />
</div>
<button onclick="addfile()">
  Add File
</button>
<button onclick="test()">
  Test
</button>
Andrew
  • 1,126
  • 11
  • 28

1 Answers1

1

I don't think this is possible since it would pose a serious security concern.

You may get the filename depending on support but exposing the path on a user's machine is very dangerous.

AndFisher
  • 633
  • 1
  • 5
  • 18