Submitting the form while replacing submitting element - using in-line onClick

This fiddle demonstrates how a submit button triggers a submit but when replaced within it's click event will not continue to submit the form. The form will have to be submitted manually instead if the element triggering the original submit has been replaced in the same process.

by Francois Wahl

HTML

<form id="myForm" action="http://jsfiddle.net/">
    <input class="button" name="save" type="submit" onclick="$(this).replaceWith('<img src=http://www.example.com/images/ajax-loader.gif />'); console.log(this); $('#myForm').submit();" value="SUBMIT">
</form>

JavaScript

//$("input[name='save']").on("click", function(){
//    $(this).replaceWith('<img class="submit-form" src=http://www.example.com/images/ajax-loader.gif />');
//    
//    window.setTimeout(function(){
//        $("form").submit();
//    }, 300);
//});

$("#myForm").on("submit", function(){
    alert("form has been submitted.");
    return false;
});