## JavaScript to Submit a Form

    window.addEventListener("DOMContentLoaded",function(){
        let form = document.getElementById('comment-form');
        form.addEventListener("submit",function(ev){
            ev.preventDefault();
            sendData(form);
        });
    });

    function sendData(form) {
        const xhr = new XMLHttpRequest();

        // Bind the FormData object and the form element
        const fd = new FormData( form );

        // Define what happens on successful data submission
        xhr.addEventListener( "load", function(ev) {
            console.log(ev.target.responseText);
            form.innerHTML = 'Thank you for your feedback.';
        } );

        // Define what happens in case of error
        xhr.addEventListener( "error", function( ev ) {
            console.log('Oops! Something went wrong.');
        } );

        // Set up our request
        xhr.open( form.getAttribute('method'), form.getAttribute('action') );

        // The data sent is what the user provided in the form
        xhr.send( fd );
    }