HTML JS
HOW TO RESET HTML FORM AFTER SUBMISSION
<form id="my-form" autocomplete="off" onsubmit="return process()"> WILL RESET TO "JON", NOT EMPTY. <input type="text" name="name" value="Jon"/>
THE HTML FORM
01
WILL REVERT TO BLANK <input type="email" name="email"/> GO! <input type="submit" value="Go!"/> </form>
function process(){ GET FORM DATA var form = document.getElementById ("my-form"); var data = new FormData(form);
JAVASCRIPT AJAX SUBMIT
02
AJAX SEND FORM var xhr = new XMLHttpRequest(); xhr.open('POST', "SERVER.SCRIPT"); xhr.onload = function () { console.log(this.response); form.reset(); }; xhr.send(data); return false; }