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 :

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


Source: html5

Leave a Reply