Horje

How to Double-click on a button to copy some text from an input field to another input field

A function is triggered when the button is double-clicked. The function copies the text from Field1 into Field2.

index.html
Example: HTML
<!DOCTYPE html>
<html>
<body>

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

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

<p>A function is triggered when the button is double-clicked. The function copies the text from Field1 into Field2.</p>

<script>
function myFunction() {
  document.getElementById("field2").value = document.getElementById("field1").value;
}
</script>

</body>
</html>

Output should be:

How to Double-click on a button to copy some text from an input field to another input field




Type:
html
Category:
Web Tutorial
Sub Category:
HTML Mouse Events Attribute
Uploaded by:
Admin