Prevent Users from Accidentally Submitting a form if Enter Key is pressed?

  • Profile Image
    greystreet41
    Asked on April 14, 2016 at 11:20 AM

    I have issues with clients accidently pressing the "enter" button on their keyboard and the form they were filling out gets submitted half done. I have always had the submit button but if my client is in a dialog box and they press enter it has submitted the form. Is there a way to only submit the form when complete?

  • Profile Image
    KadeJM
    Answered on April 14, 2016 at 12:38 PM

    I see that you are having an issue with your form accidentally being submitted if the enter key is pressed by your clients sometimes.

    While we don't have a feature that controls that sort of option yet it is possible to do this via the form's full source code which can then be re-embedded onto your webpage to prevent it.

     

    First you need to download your form's full source code.

     

    You can then try something like this -

    (1) Add this script in between the <Head></Head> of your page html:

    <SCRIPT LANGUAGE="javascript"> function testForEnter() { if (event.keyCode == 13) { event.cancelBubble = true; event.returnValue = false; } } </SCRIPT> 

     

    (2) Add this script in between the <Body></Body> of your page's html.

    <FORM id="YourForm" name="YourForm" method="GET" action="testSubmit.htm" style="background-color:orange"> <H2>YourForm: Stops form submission when user presses ENTER key.</H2> <INPUT id="textarea" name="textarea" onkeydown="testForEnter();"> <INPUT type="submit" value="Submit">

    You can swap out the id and names with your own form name and field values and your text area and textbox fields and such to prevent those from submitting when enter is pressed.