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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T11:21:02+00:00 2026-05-20T11:21:02+00:00

llo, I have a form that has two submit buttons: one accept and one

  • 0

llo,
I have a form that has two submit buttons: one accept and one cancel:

<p>
    <input type="submit" name="accio" value="accept" class="default" />
    <input type="submit" name="accio" value="cancel" class="cancel" />
</p>

I want to submit the form with jQuery using the keyboard:

$(document).ready(function() {
    $("input[type=text]").focus();
    $("input[type=text]").keydown(function(e) {
            if ((e.keycode && e.keycode == 13) || (e.which && e.which == 13)) {
                $(".default").submit();
            }
            if ((e.keycode && e.keycode == 27) || (e.which && e.which == 27)) {
                $(".cancel").submit();
            }
        });
});

and I want the parameter accio to contain accept or cancel depending on the key pressed (I process it in the server)… It works in Firefox, but not in IE nor in Chrome. Where’s my fault?

Update

Following @Sime’s I got the following code:

$(document).ready(function() {
    $("input:text").focus();
    $("input:text").keydown(function(e) {
            if (e.which == 13) {
                $("#default").submit();
            }
            if (e.which == 27) {
                $("#cancel").submit();
            }
        });
});

but it’s still not working… I think it’s with the way I submit the form… Can’t I call the submit method on a “input:submit” and expect that the correct values are passed on to the controller?

  • 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-20T11:21:03+00:00Added an answer on May 20, 2026 at 11:21 am

    try this:

    $("input[type=text]").keydown(function(e) {
         if ((e.keycode && e.keycode == 13) || (e.which && e.which == 13)) {
            $(".default")[0].click();
         }
         if ((e.keycode && e.keycode == 27) || (e.which && e.which == 27)) {
             $(".cancel")[0].click();
         }
    });
    

    could you put a way to better identify the buttons.

    $("p input.cancel")
    

    UPDATE:

    $(document).ready(function() {
        $("input:text").focus();
        $("input:text").keydown(function(e) {
                if (e.which == 13) {
                    $("#default")[0].click();
                }
                if (e.which == 27) {
                    $("#cancel")[0].click();
                }
            });
    });
    

    see this example

    UPDATE II

    this code functiona well in IE6 +, the correction is in the stopPropagation

    $('input[type="text"]').keydown(function(ev) {
    
      if (ev.which == 13 || ev.which == 27) {
    
          ev.stopPropagation();
          if (ev.which == 13)
             $("#default")[0].click();
    
         if (ev.which == 27)
             $("#cancel")[0].click();
    
          return false
      }
    
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a question about inserting values into an input field from my MYSQL
I have code below of an HTML page that includes a JS file. Function
I have overloaded << operator such that it write to file and also on
When I write input data : hel'llo print_r($_POST) display hel\'\lo and when I use
#include<stdio.h> int main() { printf(He %c llo,65); } Output: He A llo #include<stdio.h> int
for Internet Explorer, I have the current code to select a range in an
Let's say I have this little piece of code: <?php $tmp = str_split('hello world!',2);
I'm new to Boost. I'm developing a little server. I have an issue when
the most darndest thing! the following code prints out 'llo' instead of the expected
I have a string and I need to find out what was matched in

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.