473,761 Members | 2,824 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

enter event with button

i am trying to similate an "ENTER" as a key to switch focus in a
sequence of text inputs. i don't want to use "event.keyC ode" since i
want to do additional testing before i decide which text input i want
to focus next. the following are the test code i have, whenever i hit
"enter", it will act clicking the submit button. what can i do to
avoid this problem?

<!-- ############# code begins here ############ -->
<html>
<head>
<script language="JavaS cript">
function jsKeyForeward(t hisID)
{
var thatID = "t0";
if (thisID == "t0")
thatID = "t1";
if (thisID == "t1")
thatID = "t2";
if (thisID == "t2")
thatID = "t0";
document.forms[0].elements[thatID].focus();
}
function jsKeyBackward(t hisID)
{
var thatID = "t0";
if (thisID == "t0")
thatID = "t2";
if (thisID == "t1")
thatID = "t0";
if (thisID == "t2")
thatID = "t1";
document.forms[0].elements[thatID].focus();
}
function jsKeyEvent(this ID)
{
if (event.keyCode == 13 || event.keyCode == 40)
{
if (event.keyCode == 13)
event.keyCode = 40;
jsKeyForeward(t hisID);
}
else
{
if (event.keyCode == 38)
{
jsKeyBackward(t hisID);
}
}
}
</script>
</head>
<body>
<form id="form1" runat="server">
<input type="submit" name="b0" value="submit" id="b0" /><br>
<input name="t0" type="text" id="t0"
onKeyDown="java script:jsKeyEve nt(this.id);" /><br>
<input name="t1" type="text" id="t1"
onKeyDown="java script:jsKeyEve nt(this.id);" /><br>
<input name="t2" type="text" id="t2"
onKeyDown="java script:jsKeyEve nt(this.id);" /><br>
</form>
</body>
</html>
<!-- ############# code ends here ############ -->
Jul 20 '05 #1
5 2107
In article <b0************ **************@ posting.google. com>,
al*********@yah oo.com enlightened us with...
i am trying to similate an "ENTER" as a key to switch focus in a
sequence of text inputs. i don't want to use "event.keyC ode" since i
want to do additional testing before i decide which text input i want
to focus next. the following are the test code i have, whenever i hit
"enter", it will act clicking the submit button. what can i do to
avoid this problem?


Don't do this.
onKeyDown="java script:jsKeyEve nt(this.id);"
All events are script. Just do
onKeyDown="jsKe yEvent(this.id) ;"

Now, when a user presses the enter key, it is expected (in general) that
the browser will submit the form. Don't mess with that. It makes people
want to pelt you with rotten fruit.
If that's not what you meant, please clarify the question.

Oh, and the way people move from one input to another on a form is with
TAB. Not ENTER. Just in case what you actually wanted was to simulate
moving from one input to another. TAB moves inputs. ENTER submits.

HTH

--
--
~kaeli~
Condoms should be used on every conceivable occasion.
http://www.ipwebdesign.net/wildAtHeart
http://www.ipwebdesign.net/kaelisSpace

Jul 20 '05 #2
thank you for your reply.
first of all, what did you mean "All events are script"? what's the
difference between script events and non-script events?

the code i provided here, is to make "enter" key work as a "tab" key
(just because all old green screen applications are using "enter"
instead of "tab"; furthermore, if there are more than one buttons, it
will confuse the users on which button they submit.) in the same
function jsKeyEvent(..) i already make the up and down arrow
working... but just can't make the "enter" working.

my question is, if i press the "enter" key, how to waken the
jsKeyEvent event handler, to decide which input box to focus on the
next?

thankx a lot again.
kaeli <ti******@NOSPA M.comcast.net> wrote in message news:<MP******* *************** **@nntp.lucent. com>...
In article <b0************ **************@ posting.google. com>,
al*********@yah oo.com enlightened us with...
i am trying to similate an "ENTER" as a key to switch focus in a
sequence of text inputs. i don't want to use "event.keyC ode" since i
want to do additional testing before i decide which text input i want
to focus next. the following are the test code i have, whenever i hit
"enter", it will act clicking the submit button. what can i do to
avoid this problem?


Don't do this.
onKeyDown="java script:jsKeyEve nt(this.id);"
All events are script. Just do
onKeyDown="jsKe yEvent(this.id) ;"

Now, when a user presses the enter key, it is expected (in general) that
the browser will submit the form. Don't mess with that. It makes people
want to pelt you with rotten fruit.
If that's not what you meant, please clarify the question.

Oh, and the way people move from one input to another on a form is with
TAB. Not ENTER. Just in case what you actually wanted was to simulate
moving from one input to another. TAB moves inputs. ENTER submits.

HTH

--

Jul 20 '05 #3
Ivo
> kaeli <ti******@NOSPA M.comcast.net> wrote
Don't do this.
onKeyDown="java script:jsKeyEve nt(this.id);"
All events are script. Just do
onKeyDown="jsKe yEvent(this.id) ;"
"Alan Zhong" <al*********@ya hoo.com> wrote thank you for your reply.
first of all, what did you mean "All events are script"? what's the
difference between script events and non-script events?
Look carefully at the difference between the line above and the line below
that remark. Then remove the "javascript :" parts from your code.
the code i provided here, is to make "enter" key work as a "tab" key
(just because all old green screen applications are using "enter"
instead of "tab"; furthermore, if there are more than one buttons, it
will confuse the users on which button they submit.) in the same


Buttons are not submitted. Forms are. How many forms are there on your
nostalgically green page? Don't all buttons submit the same form? Unless you
know your audience, you will need to explain this customized behaviour of
the Enter key on the page because I will definetely expect a submission when
I click Enter, unless I am in a textarea or so.
In your code, you 're trying to set an event property to the value of 40.
They are read-only. I 'm not sure I see the point in that:
if (event.keyCode == 13)
event.keyCode = 40;

HTH
Ivo
Jul 20 '05 #4
On Thu, 19 Feb 2004 03:44:42 +0100, Ivo <no@thank.you > wrote:
"Alan Zhong" <al*********@ya hoo.com> wrote
[...] if there are more than one buttons, it will confuse the users
on which button they submit.) in the same


Buttons are not submitted. Forms are.


Buttons are submitted as part of the forms that contain them, if they meet
the criteria for a "successful control"[1] In that way, you can give
significance to the button pressed during processing on the server.

Mike

[1] http://www.w3.org/TR/html4/interact/...html#h-17.13.2

--
Michael Winter
M.******@blueyo nder.co.invalid (replace ".invalid" with ".uk" to reply)
Jul 20 '05 #5
In article <b0************ **************@ posting.google. com>,
al*********@yah oo.com enlightened us with...
thank you for your reply.
first of all, what did you mean "All events are script"? what's the
difference between script events and non-script events?

Any browser event (onClick, onmousedoen, onkeyup, etc) fires script, if
the author tells it to. That is, onClick is by its very nature an event
that can either be handled by script or ignored. So telling it
"javascript :" is redundant UNLESS this page is part of an ASP
application and the default language (IE only) is specified as VBScript
and you wanted it to be handled by javascript. However, most of the time
what you see is the opposite - the default is javascript but the author
wants to execute vbscript. So, it would be onClick="vbscri pt:
btn_someprocedu re"
the code i provided here, is to make "enter" key work as a "tab" key
Why? Because your users are all ancient?
I hope only YOUR users use this, because anyone else who surfs the net
will be confused as hell.
(just because all old green screen applications are using "enter"
instead of "tab"; furthermore, if there are more than one buttons, it
will confuse the users on which button they submit.) in the same
function jsKeyEvent(..) i already make the up and down arrow
working... but just can't make the "enter" working.
If you really want to prevent the enter key from submitting, you have to
catch it and stop it. This is with a keypress handler found easily via
Google.

my question is, if i press the "enter" key, how to waken the
jsKeyEvent event handler, to decide which input box to focus on the
next?


You'd have to give each textbox a tab order and somehow keep track of
which box focus was on and then set focus to the next when you catch the
enter key.
--
--
~kaeli~
Once you've seen one shopping center, you've seen a mall.
http://www.ipwebdesign.net/wildAtHeart
http://www.ipwebdesign.net/kaelisSpace

Jul 20 '05 #6

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

Similar topics

5
6823
by: Steve | last post by:
Hi, Is it possible to make hitting the enter key in an ASP textbox run the code behind an ASP button on a form? I have a search page which users tend to type in the query then just hit enter rather than actually clicking the search button, but this does not run the search code behind the button.
5
1934
by: Girish | last post by:
I have TWO submit buttons of type IMAGE on my asp form. This renders as <input type="image">. I need to be able to eble the ENTER button for both buttons. Yes, I know that for the input type image, the submit happens automatically to the server. Heres my problem: I have two event handlers for both these buttons as stated below: BUTTON 1:
5
2945
by: Eric | last post by:
Hi All, I'm very experienced in traditional ASP and am new to (am learning) ASP.NET. FYI: I am initially learning ASP.NET with VB.NET to ease the transition for me. I have encountered what I believe to be a huge limitation with ASP.NET and I'm wondering how you have handeled this problem. Let's suppose you have a page where the user can do one of two things: add a "Category", or add a "Movie Title" to an already existing category. ...
6
3812
by: guoqi zheng | last post by:
In a regular html form, when user press "enter" key, the form will be submitted. However, in ASP.NET web form, a form will only be submitted (post back) when a special button is clicked. Many user get used to click "enter" key to submit a form. How can I use "enter" key to submit/postback in ASP.NET. Thank, Guoqi Zheng
5
3134
by: ewillyb | last post by:
Hi, ASP.NET has some interesting behavior when the user hits the Enter key. If there are multiple ASP:Buttons (rendered as HTML submits) on the form, when the user hits enter, the first button's click event will fire and the page will submit. I have a series of pages with Previous and Next navigational Btns. The Previous button is the first button, so when the user hits enter, the previous page is served up. Enter should result in...
11
7764
by: Joe | last post by:
Hello All, I have an ASP.NET page with one Textbox (SearchTextBox) and one ImageButton (SearchButton) server controls. The user can type search text in SearchTextBox and click SearchButton and the web server performs a database query and displays the results. All of this works fine. I want the user to be able to press the Enter key while the cursor is still in SearchTextBox and have the SearchButton.Click event fire (thus performing...
12
7386
by: SJ | last post by:
Hope someone can help me out there I'm struggling with a particular problem... I have a form with many tab pages. On one tab page I've got a button which when clicked with a mouse adds items into a datagrid. When a user presses the enter key on this button I want the mouse click event to be activated but instead the tab page's validating event is called. I understand that this behaviour is by partly by design (Accept button etc) but I...
15
4055
by: Adam J. Schaff | last post by:
I have noticed that if a user closes a form via pressing return (either while the OK button has focus or if AcceptButton is set to OK for the form) then the "ENTER" keypress event fires ON THE CALLING FORM! This is very bad for me, because in my application, Form1 responds to an ENTER keypress by calling Form2. If the user closes Form2 via an ENTER, then Form1 just reopens it again, kind of trapping the user in Form2 (they can still close...
4
7628
by: nkoier | last post by:
Hi, I've been going crazy trying to figure out what's wrong with our Asp.Net 2.0 intranet site. At the very top of our main page I provide a TextBox and a Button for submitting Google searches. Recently somebody pointed out to me that you can't just press ENTER anymore after typing in the TextBox but that you HAVE to click on the submit Button WITH THE MOUSE for it to work. After some initial troubleshooting I discovered that it's only...
4
2402
by: portCo | last post by:
Hello there, I am using Visual Basic 2005. I want to store a value when I press enter key on the keyboard. Could anyone help me out? Thanks alot.
0
9377
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10136
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9989
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9811
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8814
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7358
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5266
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5405
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3913
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.