Solved

Submit Button Image and Enter Key

Posted on 2004-10-09
3
285 Views
Last Modified: 2012-05-05
I have this code on my login page where I have a submit button using an image. I want this button to be activated if a user presses their Enter Key.

How would I accomplish this?

<td align="center">
<input type="button" runat="server" onserverclick="DoLogin" ID="Submit1" NAME="Submit1"
                                                                                                style="BORDER-RIGHT: 0px solid; PADDING-RIGHT: 0px; BORDER-TOP: 0px solid; PADDING-LEFT: 0px; BACKGROUND-IMAGE: url(../CSS/Buttons/submit_plain.gif); PADDING-BOTTOM: 0px; BORDER-LEFT: 0px solid; WIDTH: 132px; PADDING-TOP: 0px; BORDER-BOTTOM: 0px solid; BACKGROUND-REPEAT: no-repeat; HEIGHT: 15px"></td>
0
Comment
Question by:jamesh1031
3 Comments
 
LVL 6

Expert Comment

by:ryerras
ID: 12266597
0
 
LVL 5

Accepted Solution

by:
KarcOrigin earned 500 total points
ID: 12266646
Try this:


<Html>
<Body>

<script Language="JavaScript">
// Find browser name
var isNav4, isIE4
if (parseInt(navigator.appVersion.charAt(0)) >= 4) {
      isNav4 = (navigator.appName == "Netscape") ? true : false
      isIE4 = (navigator.appName.indexOf("Microsoft" != -1)) ? true : false
}

// Check which key has been pressed
// If you press enter then submit form
function checkWhich(evt) {
      alert("Hi");
      var theKey
  if (isNav4) {
        theKey = evt.which
      } else if (isIE4) {
        theKey = window.event.keyCode
      }

      if (theKey == 13){
            alert("Hi");
            window.document.form1.submit();
      }
}
</Script>

<Form name="form1" mathod="Post">

      <input type="button" runat="server" onserverclick="DoLogin" ID="Submit1" NAME="Submit1" style="BORDER-RIGHT: 0px solid; PADDING-RIGHT: 0px; BORDER-TOP: 0px solid; PADDING-LEFT: 0px; BACKGROUND-IMAGE: url(../CSS/Buttons/submit_plain.gif); PADDING-BOTTOM: 0px; BORDER-LEFT: 0px solid; WIDTH: 132px; PADDING-TOP: 0px; BORDER-BOTTOM: 0px solid; BACKGROUND-REPEAT: no-repeat; HEIGHT: 15px" onKeyPress="checkWhich(event);">

</Form>

</Body>

Thx
0
 
LVL 18

Expert Comment

by:tusharashah
ID: 12267190
You might want to do something like following:

<body onkeydown="if(event.keyCode == 13){document.getElementById('ImageButton1').click();}">
...
<asp:ImageButton id="ImageButton1" runat="server"></asp:ImageButton>

-tushar
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now