473,396 Members | 2,092 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Cross Browser "Form Auto Submit on Enter"

Hello,
I need a piece of javascript that will allow a form to be submitted
when Enter is pressed for IE6 and 7, Firefox 2, and recent versions of
Safari. It is for a login page that has two textboxes: a "Login" and
a "Password". The "Login Button" is actually a standard image with an
onClick event handler to submit the form, because we use a mouseover
effect. (That is, it is not INPUT TYPE="IMAGE" but rather an IMAGE
tag with onclick="document.forms[0].submit()" added.)

I found some code that works in IE, which is below, but it only works
in IE. I am sure there is a simple cross-browser fragment of
Javascript that will do the trick, so please point me in the right
direction.

Here is the code I am using that only works for IE.
....
<head>
<script type="text/javascript">

function handle_keypress(e)
{
if(window.event.keyCode==13)
{
delayed_submit_form()
}
else
return false;
}

</script>
</head>

<body onKeyPress="handle_keypress(event)">
....

Thanks for any help you can give me,
Matt Garvin

Feb 8 '07 #1
2 11718
On Feb 8, 12:58 pm, mattgar...@gmail.com wrote:
Hello,
I need a piece of javascript that will allow a form to be submitted
when Enter is pressed for IE6 and 7, Firefox 2, and recent versions of
Safari. It is for a login page that has two textboxes: a "Login" and
a "Password". The "Login Button" is actually a standard image with an
onClick event handler to submit the form, because we use a mouseover
effect. (That is, it is not INPUT TYPE="IMAGE" but rather an IMAGE
tag with onclick="document.forms[0].submit()" added.)

I found some code that works in IE, which is below, but it only works
in IE. I am sure there is a simple cross-browser fragment of
Javascript that will do the trick, so please point me in the right
direction.

Here is the code I am using that only works for IE.
...
<head>
<script type="text/javascript">

function handle_keypress(e)
{
if(window.event.keyCode==13)
{
delayed_submit_form()
}
else
return false;
}

</script>
</head>

<body onKeyPress="handle_keypress(event)">
...

Thanks for any help you can give me,
Matt Garvin
I am not so sure about Safari but for ie and firefox I know that the
following works:
<html>
<script language="javascript">
function myKeyPressed(e){
e = e || window.event;
var unicode=e.charCode ? e.charCode : e.keyCode ? e.keyCode : 0;
if (unicode == 13){
document.formname.submit();
}
}
document.onkeypress = myKeyPressed;
</script>
<body>
<form name="formname" action="#" method="get">
<input name="test" type="text" value="test" size="12" />
</form>
</body>
</html>

Feb 8 '07 #2
Thank you for the code, Adam.

I tested it, and indeed it did work with IE and FF. Like you, I have
yet to test it with Safari, but it is covering the two biggies now.

Thank you,
Matt Garvin

Feb 9 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

16
by: Dave Smithz | last post by:
Hi, In summary: I want to a form to submit information via a HTTP POST, however, when using Internet Explorer I want to be able to use the back button and all the information retained....
4
by: Simon Wigzell | last post by:
Is there a way to prevent a form submitting when you press enter on a text field? Some people press enter when they finish typing in a text field out of habit I guess unconcsciously thinking it...
2
by: Questman | last post by:
Good afternoon, Does anyone have any code that implements, or approaches implementing, a cross-browser DHTML/JS solution to provide an Excel-like Grid on a web page - I'm trying to convert an...
5
by: Jared | last post by:
I'd like to display a "please wait while your file is uploading" page immediately after someone uploads a large-ish file. I know I could make something really slick with DHTML, or even something...
1
by: laredotornado | last post by:
Hi, I have a very simple form and I would like on Firefox and IE for the form to submit upon the user pressing enter in the textfield. Right now, I have <script type="text/javascript">...
0
by: huckfinn19 | last post by:
Hi all, I am using C# 2.0. Here is my problem. I have a modal form with an OK button. When the user, using tabs, activates the OK button and presses "Enter", in the Button event, I call: ...
3
by: Zytan | last post by:
I can handle DoubleClick on a ListBox to respond, not when the selection changes, but when you double click one to invoke an action. This is the same as using the keys to move the selection, then...
14
by: white lightning | last post by:
How to have <select onchange="this.form.submit()"and also a Submit button on one form? I have something like this: <form action="<?php $_SERVER; ?>" method="post"...
8
by: abcdriver | last post by:
<form name="return" method="post" action="a.jsp"> <input type="hidden" name="name" value="bb"> </form> <script language="JavaScript" type="text/javascript">...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.