Streaming live at 10am (PST)

Disable send form by hitting enter


#1

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)


#2

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


#3

This is not a valid selector https://api.jquery.com/category/selectors/


#4

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


#5

Delete your existing script.

Paste this in page settings > footer code

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

#6

Whoohoo, you rock @samliew

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


#7

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


#8

Replace with this

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

#9

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


#10

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