Please help me to understand how to trigger enter key and button in the same time. Value in the input has to trigger same on press enter key and on button "Enter" in the same time in this code. And after pressing the button, input field will clears each time.
<div id="myForm">
<input type="text" id="bedrag" />
<button type="button" onclick="check_field('bedrag');" value=''>Enter</button>
<p>Uw totaal:</p>
<p id="resultaat"></p>
</div>
<script>
var totaal = 0;
var bedrag = document.getElementById("bedrag");
bedrag.onkeydown = bereken
function bereken(e) {
if (e.keyCode == 13) {
var ingevoerdeBedrag = +document.getElementById("bedrag").value;
totaal = totaal + ingevoerdeBedrag;
document.getElementById("resultaat").innerHTML = 'Het bedrag is ' + totaal;
}
}
function check_field(id) {
var field = document.getElementById(id);
if (isNaN(field.value)) {
alert('not a number');
} else {
return myFunction();
}
}
</script>