How do i execute function "myanswer1()", when the user presses enter inside the text field? here is my code:
function myanswer1() {
var x = document.getElementById("myText").value;
var y = x*x;
document.getElementById("answersq").innerHTML = y;
}
<div class="holder" align="center" id="sq">
<h1 align="center" class="write"><u>Square Finder</u></h1>
<p align="center">
<input id="myText" type="text" placeholder="enter a number here">
<button onclick="myanswer1()" class="button1">Try it</button><p class="ans" id="answersq"></p>
The function should be executed only when the user is clicking enter inside the text field.