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 7746987
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T10:25:08+00:00 2026-06-01T10:25:08+00:00

I would like to simulate the user pressing tab then enter when they press

  • 0

I would like to simulate the user pressing tab then enter when they press enter. I know this sounds bad, but I have an asp.net web application that will only allow me to have one form with runat=”server” on it so when the user hits return the main form gets submitted. I have another textbox on the page though (that ideally should have it’s own form but can’t because it is asp), and when enter is hit from there obviously the main form is submitted. The simplest way I could think is to simulate tab then enter using javascript, but I have been unsuccessful in that. I am welcome to any other solutions to this problem. So far I have simulated pressing tab, but I don’t know how to simulate more than one keypress though.

Here is the code I have so far, I imagine return 9; needs to be replaced with something else. JQuery will also do.

function suppressEnter (e) {
    var keyPressed;
    if (window.event) { keyPressed = window.event.keyCode }  // IE
    else if (e) { keyPressed = e.which };  // Netscape
    if (keyPressed == 13) {
        return 9;
    }
    else {
        return true;
    }
}

EDIT: return 9 + 13; works in chrome, but not IE

  • 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-01T10:25:09+00:00Added an answer on June 1, 2026 at 10:25 am

    Something like this would work:

    function keyPress(e) {
        if (e.which == 13) {
             $(document).trigger(jQuery.Event('keydown', {which: 9}));
            // do something
            alert('Enter')
        }
        if (e.which == 9) {
             // do something
             alert('Tab');
        }
    
    };
    
    $(document).bind("keydown", keyPress);
    

    I’ve coded it up in a fiddle – http://jsfiddle.net/FAe6U/


    Also With regards to @nnnnnn comment:

    It seems to me you should just code that directly rather than trying
    to simulate keystrokes.

    Try this:

    var tabPress;
    function keyPress(e) {
        if (e.which == 13) {
            if (tabPress == 1){
                e.preventDefault();
                alert('tab and enter');
            }
            else{e.preventDefault(); alert('enter')}
        }
        else if (e.which == 9) {
            e.preventDefault();
            tabPress = 1;
        };
    };
    
    function keyRelease(){tabPress = 0;}
    $(document).bind("keydown", keyPress);
    $(document).bind("keyup", keyRelease);
    

    I’ve coded it up in a fiddle – http://jsfiddle.net/f4Ybn/

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

Sidebar

Related Questions

I don't know what exactly this feature is, but I would like to simulate
I would like to simulate a user pressing shift-enter in a text area. Here
I know there are other similar questions, but I would like to know specifically
I am rendering textured quads from an orthographic perspective and would like to simulate
Would like to know what a programmer should know to become a good at
Would like to know the c# code to actually retrieve the IP type: Static
Would like to know how to integarate cruise control with maven? Cruise Control comes
Would like to know how to hide an div after a set of css3
I would like to connect to a clustered Oracle database described by this TNS:
I would like to create an animation which enables the user to go backward

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.