What is JotForm?
JotForm is a free online form builder which helps you create online forms without writing a single line of code. No sign-up required.

At JotForm, we want to make sure that you’re getting the online form builder help that you need. Our friendly customer support team is available 24/7.

We believe that if one user has a question, there could be more users who may have the same question. This is why many of our support forum threads are public and available to be searched and viewed. If you’d like help immediately, feel free to search for a similar question, or submit your question or concern.


  • Profile Image

    Prevent form submit when hitting Enter key

    Asked by Helenium on April 07, 2016 at 10:01 PM

    RE: <script type="text/javascript">


    function stopRKey(evt) {
      var evt = (evt) ? evt : ((event) ? event : null);
      var node = (evt.target) ? evt.target : ((evt.srcElement) ? evt.srcElement : null);
      if ((evt.keyCode == 13) && (node.type=="text"))  {return false;}
    }

    document.onkeypress = stopRKey;

    </script>

    I put that script on my page (I use Dreamweaver and know how to do that) and it still submits the form when pressing the <enter> key. Even worse, I have a conditional calculation on my form, that says to check one box if you're a NY State resident and the other if you're not. Hitting "return" defaults to NY State, causing sales tax to be added as the form submits.

    I can see from reading the other answers to this question that JotForm doesn't think this is a necessary option, but if that's the best you've got, JotForm won't work for us! We can't have clients receiving receipts saying sales tax has been automatically added when it shouldn't be.

    script javascript
  • Profile Image
    JotForm Support

    Answered by jonathan on April 07, 2016 at 10:25 PM

    Hi,

    Can you share to us the URL of your website where we can test your form and the custom script.

    We will be able to provide the appropriate suggestion/solution once we know more details and information.

    We will wait for your response.

  • Profile Image
    JotForm Support

    Answered by jonathan on April 07, 2016 at 10:45 PM

    I made a test page here applying the javascript code provided by our colleague.

    If you test by hitting enter key on your keyboard, the form will not submit even if you had the cursor focus within the form.

     

     

     

  • Profile Image

    Answered by Helenium on April 08, 2016 at 12:45 PM
    Thanks for working on this issue!
    The first time I tried your form, it submitted when hitting the enter key on
    my computer. The second time it did not. I played with it on my form and
    figured out what the problem is. On either form, if the cursor is over the
    form, hitting the enter key submits the form. If the cursor if placed
    outside the form, it will not submit when the enter key is hit (and on my
    form it changes no sales tax to NY State sales tax). Try it with your form
    by selecting a country. While it is being selected, the area of the form is
    highlighted yellow and the country field has a blue outline. Hit enter, and
    the form submits. I hope this helps you figure out what other code is needed
    to prevent that.
    Also note another little glitch Ive found: Hitting Clear Form clears
    everything except the Sales Tax, which displays the NY State sales tax for
    whatever amount was put in there, i.e. if you put 500 in the purchase price
    form, the NY tax is 44.38. Clear the form and the 44.38 stays in the Sales
    Tax and Balance Due fields.
    I have been using a Hot Dreamweaver product for these forms for a long time,
    but now I want to use a server-side include for a new mobile-friendly
    navigation bar and when I do, its disabled the form. So I have to find
    something else. I can see that Jotform will work with the new navigation bar
    as a server-side include (Ive turned the SSI off and put the full
    navigation menu code on the page below, because when I use SSI theres a
    conflict with the current purchase forms, but Ive tested SSI with the
    Jotform and it does work). Jotform does have some other nice features that
    improve on what we have, so Id be happy to use it if we fix these glitches.
    Here is my test form URL:
    http://www.georgeglazer.com/purchase-chkJotformMGM.html
    --Helen
    ...
  • Profile Image

    Answered by Huberson on April 08, 2016 at 02:22 PM

    I have tested the form  provided by my colleague above - test page here and the one on your website - http://www.georgeglazer.com/purchase-chkJotformMGM.html but was not able to reproduce any of the scenario you mentioned above.

    I get the same with Chrome and Firefox, with the cursor over the form or outside. The clear button seems also clearing all the form fields.

    Are you adding any additional Script beside the one provided above that could cause this?

  • Profile Image

    Answered by Helenium on April 08, 2016 at 05:09 PM

    No, still happens to me. I'm on Mac OS 10.10 Yosemite, using the Chrome browser. I made a screen recording of your form. Note position of cursor at the end. Then I let go of the mouse and hit the enter key and the form submitted.  There is no place here to upload MOV files so I'll email it to you.

     

     

  • Profile Image

    Answered by Helenium on April 08, 2016 at 05:45 PM
    I just replied on the forum page but was unable to upload the screen
    recording, so Ive attached it here.
    As I said there:
    No, still happens to me. I'm on Mac OS 10.10 Yosemite, using the Chrome
    browser. I made ascreen recording of your form. Note position of cursor at
    the end. Then I let go of the mouseand hit the enter key and the form
    submitted. There is no place here to upload MOV files so I'll email it to
    you.
    --HG--
    ...
  • Profile Image
    JotForm Support

    Answered by Mike on April 08, 2016 at 07:29 PM

    Try the following script. It should disable the Enter key everywhere, but excluding a text area element.

    <script type="text/javascript">

    function stopRKey(evt) {
      var evt = (evt) ? evt : ((event) ? event : null);
      var node = (evt.target) ? evt.target : ((evt.srcElement) ? evt.srcElement : null);
      if (evt.keyCode == 13 && node.nodeName != "TEXTAREA")  {return false;}
    }

    document.onkeypress = stopRKey;

    </script>

    Thank you.

  • Profile Image

    Answered by Helenium on April 14, 2016 at 05:33 PM

    The script you posted at 7:29 pm on April 8th does work to keep the form from submitting when the Enter key is pressed, so that's good.

    However, there is still a problem remaining -- clicking the Submit button causes the "Outside NY State" box to switch to "NY State Resident" and add sales tax to the total. Can't use the form unless that is fixed, too.
  • Profile Image

    Answered by Huberson on April 14, 2016 at 07:13 PM

    Is it possible to make a screenshot and upload it so we can see the changes on the form when you submit it. You can use MakeGif Capture  Chrome Extension to convert your screen-cast so it can be uploaded here.

    I have checked you form but could not replicate the issue.

     

    We will be waiting for your reply.

  • Profile Image

    Answered by Helenium on April 14, 2016 at 09:40 PM

    I downloaded that MakeGIF extension, but when I click on the icon in the toolbar, it tells me "No HTML5 video found on this page." There's a "Load Local Video/Webcam" link, but that takes me to a page saying "The URL makegif.com is available." So I deleted the extension from my browser.

    I did make a screen recording showing the issue which I have emailed to you. 

    --Helen

  • Profile Image

    Answered by Helenium on April 14, 2016 at 09:45 PM
    Here is the screen recording you requested showing what happens when the
    Submit button is pressed, and how it changes $0 tax to the amount required
    for NY State sales tax.
    --Helen
    ...
  • Profile Image
    JotForm Support

    Answered by jonathan on April 14, 2016 at 11:07 PM

    From what I have reviewed on this thread, the original issue regarding the Submission when hitting Enter key was already resolved. We can closed this thread then.

    Do let us know if there is still remaining unresolve issue about it. 

    --

    The latest issue you have described was about a different feature, so I created a dedicted thread for it here so that the support team can dedicate time to work on it.

    https://www.jotform.com/answers/819068

     

    Thank you.

  • Profile Image

    Answered by dcampagna on September 14, 2016 at 10:52 AM

    As noted by others, I don't want to have every field required; some are optional. The some fields will be blank, and others will be filled. 

    This is really, really dumb. People naturally hit "Enter" and expect to get to the next line or field, not submit the form. In that case -- why even have a "Submit" button at all?

    How is adding a Javascript to the code "resolved"? It's a feature that your customers have been asking for for FOUR years. Why not implement it? And if you're saying you can't implement it, then why would we have confidence in your company going forward?

  • Profile Image
    JotForm Support

    Answered by Chriistian on September 14, 2016 at 12:27 PM

    Hi dcampagna,

    I have moved your concern to a separate thread so we can better assist you. Please check the thread here: https://www.jotform.com/answers/932118