0

Value is not working for type="file"

<html>
  <body>
  <input type="file" id="myText">
  <script>
  document.getElementById("myText").value = "Johnny Bravo";
  </script>
  </body>
</html>

1

2 Answers 2

1

Input Type file cannot be filled with any value. The choosen file will be shown only on selection of the file. Perhaps, you could get the value and show as preview image/video.

1

For security reason, the input[type='file'] is not changeable via JavaScript.

For example, if you can change the value of input[type='file'] via JavaScript, you can read any file content from client's local machine, it is potential risk, right?

Not the answer you're looking for? Browse other questions tagged or ask your own question.