var yourElement = document.getElementById("yourElementID"); yourElement.addEventListener("submit", function(e) { if(something) e.preventDefault(); // // stop form submission // add your code HERE });