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

  • Home
  • SEARCH
  • 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 8634819
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T09:48:50+00:00 2026-06-12T09:48:50+00:00

I am having a difficult time with keydown and stop propagation i do not

  • 0

I am having a difficult time with keydown and stop propagation

i do not want my page to refresh, i have tried every which way i can think of, my current code is

 <script>
 $(document).ready(function() {
 var e = jQuery.event( 'keydown', { which: $.ui.keyCode.ENTER } );

 $('#id_number').trigger(e, function(event){
event.preventDefault();
event.stopPropagation();
});

 });
 </script>

any idea on what i am doing wrong here? I thought that the event was called correctly, i have jquery and jquery ui linked correctly and receive no console errors

UPDATE
well it was working, now im getting
Property ‘event’ of object function (a,b){return new e.fn.init(a,b,h)} is not a function
error on the below code

 $(document).ready(function() {
 var e = jQuery.event( 'keydown', { which: $.ui.keyCode.ENTER } , function(event){
  event.preventDefault();
  event.stopPropagation();
}); 

 $('#id_number').trigger(e);

 });

UPDATE #2 – fixed

things I learned

  1. trigger() not needed in the document(ready)
  2. getting $.ui.keyCode to work was difficult (at least for me)
  3. always see what other functions are attached to the input (onblur, onfocus, ect) aka doh

rewrote it to this, works perfectly fine

 $(document).ready(function() {
    $('#id_number').keydown(OnKeyDown);
 });    

function OnKeyDown(e){
var code = (e.keyCode ? e.keyCode : e.which); //to support both methods
if(code == 13) { //the Enter keycode

    //my actions
 return false;
 }
}
  • 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-06-12T09:48:52+00:00Added an answer on June 12, 2026 at 9:48 am

    The code to stop the default action must go to the element that the event applies to..

    $('#id_number').keydown(function(event){
      event.preventDefault();
      event.stopPropagation();
    });
    

    The .trigger() second argument is for extraParameters

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

Sidebar

Related Questions

Hey all, I'm having a difficult time wording this properly which is why im
I am new to JavaScript (but not programming) and am having a difficult time
Ok, I have looked all over and I am having a difficult time trying
I am having a difficult time trying to set up Cruise (not cruise control)
I'm having a difficult time understanding how to do this. I have two models,
I'm having a difficult time finding definitive information on this. If I have a
I'm having a difficult time understanding what's going wrong. I have an NSWindowController with
I am having a difficult time forming a conditional INSERT I have x_table with
I am having a difficult time trying to find a way to link the
I'm having a difficult time trying to work out how to build a page

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.