473,396 Members | 1,766 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.

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.keyCode" 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="JavaScript">
function jsKeyForeward(thisID)
{
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(thisID)
{
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(thisID)
{
if (event.keyCode == 13 || event.keyCode == 40)
{
if (event.keyCode == 13)
event.keyCode = 40;
jsKeyForeward(thisID);
}
else
{
if (event.keyCode == 38)
{
jsKeyBackward(thisID);
}
}
}
</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="javascript:jsKeyEvent(this.id);" /><br>
<input name="t1" type="text" id="t1"
onKeyDown="javascript:jsKeyEvent(this.id);" /><br>
<input name="t2" type="text" id="t2"
onKeyDown="javascript:jsKeyEvent(this.id);" /><br>
</form>
</body>
</html>
<!-- ############# code ends here ############ -->
Jul 20 '05 #1
5 2089
In article <b0**************************@posting.google.com >,
al*********@yahoo.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.keyCode" 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="javascript:jsKeyEvent(this.id);"
All events are script. Just do
onKeyDown="jsKeyEvent(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******@NOSPAM.comcast.net> wrote in message news:<MP************************@nntp.lucent.com>. ..
In article <b0**************************@posting.google.com >,
al*********@yahoo.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.keyCode" 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="javascript:jsKeyEvent(this.id);"
All events are script. Just do
onKeyDown="jsKeyEvent(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******@NOSPAM.comcast.net> wrote
Don't do this.
onKeyDown="javascript:jsKeyEvent(this.id);"
All events are script. Just do
onKeyDown="jsKeyEvent(this.id);"
"Alan Zhong" <al*********@yahoo.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*********@yahoo.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.******@blueyonder.co.invalid (replace ".invalid" with ".uk" to reply)
Jul 20 '05 #5
In article <b0**************************@posting.google.com >,
al*********@yahoo.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="vbscript:
btn_someprocedure"
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
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...
5
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...
5
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...
6
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...
5
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...
11
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...
12
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...
15
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...
4
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....
4
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
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
0
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,...
0
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...
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.