Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7695049
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T21:27:29+00:00 2026-05-31T21:27:29+00:00

On my forms I prevent the user from submitting the form by clicking enter

  • 0

On my forms I prevent the user from submitting the form by clicking enter in text elements however, I want to allow them to use the enter key to submit the form when the button element has focus. Currently, it only works with the spacebar. I’ve tried the following:

$("#dyn-gen-form").on("keypress", "#genAttFormBtn", function(e) {
  e.preventDefault();
  log("pressed a key");
  var k = e.keyCode || e.which;
  if (k == 13) {
    // do the work
    return false;
  }
});

But it isn’t working. By isn’t working, I mean, the event isn’t triggered. I get nothing.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T21:27:30+00:00Added an answer on May 31, 2026 at 9:27 pm

    I made a sample for you: http://jsfiddle.net/p7vzJ/54/ – button detects spacebar as well as enter key stroke; Please press space or enter after the jsfiddle is loaded.

    I can remove my post if you don’t wanna use .live Please let me know.

    JQuery Code

    $(document).ready(function() {
    $("#genAttFormBtn").focus();
    $("#dyn-gen-form").live("keydown", "#genAttFormBtn", function(e) {
        e.preventDefault();
        //log("pressed a key");
        if(e.keyCode == 32) {
            alert('whitespace');
            $("#previous").click();
        } else if(e.keyCode == 13) {
           alert('enter');
        }
    });
    
    });​
    

    cheers!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to prevent the user from maximizing the Windows Form to full screen
How do I prevent my user from submitting an empty form? When I do
After processing form from POST I should redirect, to prevent user from hitting back.
How do I prevent my form from being resized? I don't want it to
I want to display an overlay when the user is submitting a form. I'm
So as the title says i want to prevent user from keep submiting $_POST
I want to prevent a form from being submitted using jQuery and instead run
I am trying to find a way to prevent users from double-submitting my forms.
Suppose I have a form and I wanna prevent the user from submiting the
Is there a way to prevent empty elements of the form <myElement/> being used

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.