How to get input values while click with enter key in text field and button click

Manideepgoud
Posted by Manideepgoud under JavaScript category on | Points: 40 | Views : 145
<!DOCTYPE html>
<html>
<head>
<title>Javascript</title>
</head>
<body>
<input type="text" placeholder="Add" id="myvalue" />
<button type="submit" onclick="myfunction()">Add</button>
<p id="demo"></p>
</body>
<script>
function myfunction() {
document.getElementById("demo").innerHTML += document.getElementById("myvalue").value + "<br/>";
}
var input = document.getElementById("myvalue");
input.addEventListener("keyup", function(event) {
debugger;
if (event.keyCode === 13) {
myfunction();
}
});
</script>
</html>

Comments or Responses

Login to post response