I have made a simple code that changes the heading when you input text in the input, but I want the event to trigger when I press the enter key as I have to press the button to get it to work, is there a piece of code I can implement to have his work? cheers.
function block() {
var myValue = document.getElementById('textBox').value;
if (myValue.length == 0) {
alert('Please fill with valid text');
return;
}
var myTitle = document.getElementById('Heading');
myTitle.innerHTML = myValue;
};
<!DOCTYPE html>
<html>
<head>
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Raleway:wght@100&display=swap" rel="stylesheet">
<link rel="stylesheet" href="fundamentals.css">
<script src="fundamentals.js"></script>
<title>Javscript</title>
</head>
<body>
<h1 id="Heading">This is a heading</h1>
<input type="text" id="textBox">
<input type="submit" value="Click Me" onclick="block()">
</body>
</html>