[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

Submit Button Image and Enter Key

Posted on 2004-10-09
3
Medium Priority
?
294 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 6

Expert Comment

by:ryerras
ID: 12266597
0
 
LVL 5

Accepted Solution

by:
KarcOrigin earned 1500 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

 [eBook] Windows Nano Server

Download this FREE eBook and learn all you need to get started with Windows Nano Server, including deployment options, remote management
and troubleshooting tips and tricks

Question has a verified solution.

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

This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
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…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …

650 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