Disable send form by hitting enter

Hi,

I’ve noticed that when I switch form setting to “post” it automatically enables sending the form by hitting enter on the keyboard, which I don’t like. I’ve tried including this bit of JS

$('myform').submit(function() {
  return false;
});

I’ve changed ‘myform’ to my form ID but unfortunately no luck.

Can anyone suggest how to disable this?

Thanks!


Here is my public share link: LINK
(how to access public share link)

My JavaScript knowledge isn’t very good I’m afraid but could it be possible that the script is loading before the DOM is ready and available to it?

Best wishes,

Mark

This is not a valid selector Selectors | jQuery API Documentation

@samliew Unfortunately I am not a JS pro as well :open_mouth: maybe you can elaborate more? thx

Delete your existing script.

Paste this in page settings > footer code

$('#email-form').submit(function() {
  return false;
});
4 Likes

Whoohoo, you rock @samliew

so simple. but I wouldn’t ever have a clue :slight_smile:
Thanks!

Actually I’ve just realised it is a bad solution :frowning:
I didn’t notice at first but it actually prevents the form sending even by mouse clicking on the send button. I’m using this code instead now, It works but I’d love to be able to create new paragraphs within text area by hitting enter, I only want to avoid sending the form by enter. Anyone please?

<script>
$(function () {
     $(window).keydown(function (event) {
        if (event.keyCode == 13) {
              event.preventDefault();
               return false;
         }
     });
})
</script>

@samliew

Replace with this

<script>
$(function() {
   $('.w-button').attr('type', 'button').click(function() {
      $(this).parents('form').submit();
   });
})
</script>
1 Like

Nope, that doesn’t allow me to make a new paragraph within the message area…

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.