jqueryformsform-submitonpaste

jQuery: Submit form on paste


A data entry person is putting email address into a form and it would be helpful if the form submitted each time he pasted in an address so it would be ready for the next paste. Other code within the setTimeout also works fine--just not the form submission. Thanks in advance for your help.

$("#email").on("paste", function(){
    setTimeout(function () {
        $("#cancelemail").submit();
    }, 0);
});


<form action="done.php" method="post" id="cancelemail">

Address to be removed: <input id="email" name="email" type="text" />

<input type="submit" name="submit" value="Remove">

</form>

Solution

  • That's strange, triggering the submit doesn't seem to be working for me unless I remove the submit button from the HTML, but triggering the submit button actually does ?

    $("#email").on("paste", function () {
        setTimeout(function() {
            $('[name=submit]').trigger('click')
        });
    });
    

    Fiddle with button, triggering submit -> not working ?
    Fiddle without button, triggering submit -> works
    Fiddle with button, triggering button click -> works