Whenever the keyboard's enter key is pressed for the first time, it should trigger the button with id="botonCorregir". However, on the second press of the enter key, it should execute a function named url(). I have used a variable called cont to differentiate between the two actions in my JavaScript code. Despite my efforts, there seems to be an issue preventing it from working as intended.
Thank you!
Here is the relevant HTML:
<input id="respuestaUsuario"></input>
<button id="botonCorregir">Reply</button>
<a id="enlaceSiguiente" href="nextQuestion.html">Next question</a>
And the corresponding JavaScript:
<script>
var cont=0;
if(cont==0){
// Should respond to the first press of enter
var input = document.getElementById("respuestaUsuario");
console.log('input: ', input)
input.addEventListener("keyup", function(event) {
if (event.keyCode == 13) {
event.preventDefault();
document.getElementById("botonCorregir").click();
}
});
cont++;
}else{
// Should respond to the second press of enter
if (event.keyCode == 13) {
event.preventDefault();
document.getElementById("enlaceSiguiente").click();
}
}
</script>