I have a hidden form, due to two forms on the same page doing different submissions. The hidden form is then holding the password field that once entered it will show a section to the user, this part is all working with PHP and when the button is clicked. However, I have a addEventListener
on the input field to listen out for when the user presses 'Enter'. Within the Event Listener I have declared the name of the button and then click()
method to submit the form. But I run into the following error:
Uncaught TypeError: this.confirmPassowrd() is not a function?
JS
enterKey()
{
document.querySelector('#password-confirm').addEventListener('keydown', function (e) {
if (e.key === 'Enter') {
this.confirmPassword();
}
});
}
confirmPassword()
{
document.getElementById('confirm-password').click();
}
I'm not entirely sure what is happening, but if I put this as a normal function on the page where the html is, and call it it withing the enterKey() method it works fine. Any suggestions?
Kind regards,
James