How can I stop HTML form from reloading the page [duplicate]
You need to use the preventDefault()
method of the event object.
Note that neither addEventListener()
nor preventDefault()
are supported in IE <= 8.
var form = document.forms[0];
form.addEventListener("submit", function(evt){
var email = form.elements['answer_13829'].value;
if( email == '[email protected]') {
evt.preventDefault();
alert('redirecting the user...');
window.location = 'xxxx';
}
});