I am currently tackling a security project in Javascript, a language I am not very familiar with, and I seem to be encountering some difficulties with EventListeners.
Here is an excerpt of my code:
function prevclick(evt) {
evt.preventDefault();
document.loginform.submitbtn.removeEventListener('click',prevclick,false);
var req = new XMLHttpRequest();
req.open("GET","testlog.php?submission=complete",false);
req.send();
document.loginform.submitbtn.click(); //attempted this and loginform.submit()
}
document.loginform.submitbtn.addEventListener('click',prevclick,false);
The issue I am facing is that the submit button does not trigger form submission on the first click (it does, however, send the HTTP request on the first click), but works as expected on the second click.
My suspicion is that there might be a synchronization problem, but it is essential for me to ensure that the request is processed before redirecting the user to the next page.
If you have any insights or solutions to this problem, I would greatly appreciate your input.