function SendForm( data ) { const xmlhttp = new XMLHttpRequest(); var formdataobj = new FormData(form); // if the the send succeeds this will give us the status xmlhttp.addEventListener( "load", function(event) { alert( event.target.responseText ); } ); // if the send fails this will give us the status xmlhttp.addEventListener( "error", function( event ) { alert( 'Something went wrong.' ); } ); xmlhttp.open( "POST", "contact.php" ); xmlhttp.send( formdataobj); //get hold of the form we created earlier and bind a event listener to it. var form = document.getElementById( "myForm" ); form.addEventListener( "submit", function ( event ) { event.preventDefault(); sendForm(); } ); }