Copy file name from Text box to another Text box using Javascript

I have two input tags, One is of type=”file” another one is text.

When I select the file , the file name by default will appear in the text box whose type is file, but I want it to reflect in another text box as well.

MyCode :

function sync()
  var n1 = document.getElementById('n1');
  var n2 = document.getElementById('n2');
  n2.value = n1.value;
<input type="file" name="n1" id="n1" onkeyup="sync()"><br><br>
<input type="text" name="n2" id="n2"/>

Source: html5

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.