Javascript DOM HTML Input Text copy value

Introduction

Click on a button to copy some text from an input field to another input field:

View in separate window

<!DOCTYPE html>
<html>
<body>

Field1: <input type="text" id="field1" value="Hello World!"><br>
Field2: <input type="text" id="field2"><br><br>

<button onclick="myFunction()">Copy Text</button>

<script>
function myFunction() {//from w  w w  .j  a  v a 2 s . com
  document.getElementById("field2").value = document.getElementById("field1").value;
}
</script>

</body>
</html>



PreviousNext

Related