How to stop form submitting when 'enter' is pressed?

  • ksiraj
    Asked on March 31, 2014 at 9:14 AM

    A user (on Sarari) was filling in the form and everytime he pressed enter, the form submitted.  How do I stop this happening?

    Thanks

  • Carina
    Replied on March 31, 2014 at 10:59 AM

    I will look further for a code solution on this and will get back to you.

    Thank you

  • Carina
    Replied on April 6, 2014 at 4:04 PM

    It is necessary that you download and edit the form's source code: 

    How to stop form submitting when enter is pressed? Image 1 Screenshot 20

    Now it is necessary that you paste only the green parts into your form's source code. The script part is inserted inside the <head> tag. The "onkeydown" needs to be added to all the fields where we wish to disable enter key:

    <pre>

    <HTML>

    <HEAD>

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

    </HEAD>

    <BODY>

    <FORM id="FORM2" name="FORM2" method="GET" action="testSubmit.htm" style="background-color:lightblue"> <H3>Form2: Stops form submission when user presses ENTER key.</H3> <INPUT id="text2" name="text2" onDISABLEDkeydown="testForEnter();"> <INPUT type="submit" value="Submit">

    </FORM>

    </BODY>

    </HTML>

    </pre>

    You can test this form. Only the name field has this code associated, because it is important to keep the enter function on the comment box:

    https://shots.jotform.com/carina/html/test_prevent_enter_key.html

    Let us know if we can be of assistance.

    Thank you

  • David JotForm Support Manager
    Replied on May 17, 2016 at 4:56 PM

    For some reason your reply seems to have come empty, please let us know if you need more help we will be glad to assist you.

  • ksiraj
    Replied on May 18, 2016 at 3:44 AM
    Hi, thanks for the message, the matter is solved so no further action
    required. Thank you.
    Kate
    Kate Siraj
    Ayurvedic Practitioner
    BSc Ayurveda (Manipal), MChem (Oxon), MAPA
    020 3166 5086 / 07980 285 268
    22 Hogarth Way, Hampton, TW12 2EL
    www.theayurvedapractice.com
    ...
  • PCIrish
    Replied on June 6, 2016 at 7:40 PM

    This is nuts.  If I could figure out how to do this, I probably would not have needed JOTFORM in the first place.  Please, Jotform, give us another solution.

  • David JotForm Support Manager
    Replied on June 6, 2016 at 8:47 PM

    @PCIrish, I see you have opened a thread for your concern: https://www.jotform.com/answers/854877, you will be assisted there, thanks.