Solved

Submit Button Image and Enter Key

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
display data in text field from data base for updating 6 50
Memory Usage 2 49
Run time Error 4 34
Visual Studio TFS - how do I check in my code? 2 28
For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
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…

932 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

12 Experts available now in Live!

Get 1:1 Help Now