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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T03:52:55+00:00 2026-05-18T03:52:55+00:00

In a C#/ASP.NET application, I have a form that renders much like the following

  • 0

In a C#/ASP.NET application, I have a form that renders much like the following (plus a lot more, but this is what matters):

<form method="post" action="">
<input type="image" name="ctl15" src="cancel.gif" style="border-width:0px;" />
    <!-- Server side, the above input is a System.Web.UI.WebControls.ImageButton. -->
...more extra fluff...
<input type="submit" name="Button1" value="Proceed" id="Button1" class="button"
    style="width:59px;" />
</form>

This form works just fine in Internet Explorer and Firefox, but fails in WebKit-based browsers (Safari and Chrome). The problem is that when the user presses Enter when in an input field, rather than using the mouse to click on the submit button, the image input is activated (which in this case corresponds to a cancel event, exactly the opposite of the “proceed” action that is natural given the UI in question).

What I want to do is to, on an Enter keypress, activate the <input type="submit"> button instead of the <input type="image">, without breaking submission by clicking the image. How can I do that? Preferably in a cross-browser manner so I don’t need yet more special cases in the code.

No jQuery solutions, please, since this application doesn’t use it (and introducing a whole new library for such a “simple” thing is going to be a very hard sell) – stock JavaScript is perfectly fine, though. Obviously the best would be if it can be done in just HTML and CSS, but I have my doubts about the feasibility of that.

In essence, this question seems to me to be sort of the exact opposite of HTML: Submitting a form by pressing enter without a submit button.

Unfortunately, since the different parts of the UI are rendered by different classes and kept in separate .aspx files (specifically, the <input type="image"> is in one place, and the <input type="submit"> in quite another), reordering the elements in the generated HTML is not really a feasible solution either.

  • 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-18T03:52:55+00:00Added an answer on May 18, 2026 at 3:52 am

    Pure JavaScript:

    <script type="text/javascript">
    var SUBMIT_BUTTON_ID = "Button1";
    window.onload = function(event) {
        var arrInputs = document.getElementsByTagName("input");
        for (var i = 0; i < arrInputs.length; i++) {
            var oCurInput = arrInputs[i];
            if (oCurInput.type == "text") {
                oCurInput.onkeypress = function(evt) {
                    if (typeof evt == "undefined" || evt == null)
                        evt = window.event;
                    var keyCode = evt.keyCode || evt.which;
                    if (keyCode == 13) {
                        document.getElementById(SUBMIT_BUTTON_ID).click();
                        return false;
                    }
                    return true;
                }
            }
        }
    }
    </script>
    

    Tested on IE8 and Chrome, better test on all browsers you think relevant before using it.

    This code will handle all onkeypress events for all textboxes in the document and when ENTER key is pressed it will imitate click of the submit button and cancel further handling of the event to avoid conflicts.

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

Sidebar

Related Questions

No related questions found

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.