I need assistance understanding how to simultaneously trigger the enter key and button in this code. When the value is entered into the input field, it should trigger both the enter key and the button "Enter" at the same time. Additionally, after pressing the button, the input field should clear each time.
<div id="myForm">
<input type="text" id="bedrag" />
<button type="button" onclick="check_field('bedrag');" value=''>Enter</button>
<p>Your total:</p>
<p id="result"></p>
</div>
<script>
var total = 0;
var amount = document.getElementById("bedrag");
amount.onkeydown = calculate
function calculate(e) {
if (e.keyCode == 13) {
var enteredAmount = +document.getElementById("bedrag").value;
total = total + enteredAmount;
document.getElementById("result").innerHTML = 'The amount is ' + total;
}
}
function check_field(id) {
var field = document.getElementById(id);
if (isNaN(field.value)) {
alert('not a number');
} else {
return myFunction();
}
</script>