Solved

Submit Button Image and Enter Key

Posted on 2004-10-09
3
288 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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The object model of .Net can be overwhelming at times – so overwhelming that quite trivial tasks often take hours of research. In this case, the task at hand was to populate the datagrid from SQL Server database in Visual Studio 2008 Windows applica…
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

785 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