Click on a button to copy some text from an input field to another input field: - Javascript DOM Event

Javascript examples for DOM Event:onclick

Description

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

Demo Code

ResultView the demo 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() {//w ww  . jav a 2 s  .  c  o m
    document.getElementById("field2").value = document.getElementById("field1").value;
}
</script>

</body>
</html>

Related Tutorials