Solved

Submit Button Image and Enter Key

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

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

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

Flash (http://en.wikipedia.org/wiki/Adobe_Flash) has evolved over the years to where it has become a masterful tool for displaying content screen.  It has excellent layout placement, UI precision as well as rendering capabilities. This, along with t…
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…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

737 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