473,503 Members | 5,495 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Help with javascript (again)

I'm not that great at reading javascripts.

Instead of doing nothing I'd like to return a Tab-character, if Enter
occurs:

<script language="javascript" type="text/javascript" >
//disable enter-key
function kH(e) {
var pK = e ? e.which : window.event.keyCode;
return pK != 13;
}
document.onkeypress = kH;
if (document.layers) document.captureEvents(Event.KEYPRESS);
</script>

To help me undertand: What is "e"? What is "!=" ? (i'm used to vb).

Regards /Snedker
Dec 5 '06 #1
5 1449
Hi Morten,
Instead of doing nothing I'd like to return a Tab-character, if Enter
occurs:

<script language="javascript" type="text/javascript" >
//disable enter-key
function kH(e) {
var pK = e ? e.which : window.event.keyCode;
return pK != 13;
}
document.onkeypress = kH;
if (document.layers) document.captureEvents(Event.KEYPRESS);
</script>
you want to retrun a Tab, but to whom? This example script will disable the
enter key simply be looking for the keyCode (which is something like the
ASCII code).

Maybe you should ask what you do instead?!

--
Best regards | Schöne Grüße
Michael

Microsoft MVP - Most Valuable Professional
Microsoft MCAD - Certified Application Developer

http://weblogs.asp.net/mschwarz/
http://www.ajaxpro.info/
Dec 5 '06 #2
On Tue, 5 Dec 2006 15:07:54 +0100, "Michael Schwarz"
<no****@schwarz-interactive.dewrote:

I wish to move to the next field in the tab-index. I reckon it is
something like nextfield.focus - but still, I don't know where to put
it.

I guess what I'm really missing is a Javascript Beginners Guide. :-)

But till then? ;-)
>Instead of doing nothing I'd like to return a Tab-character, if Enter
occurs:

<script language="javascript" type="text/javascript" >
//disable enter-key
function kH(e) {
var pK = e ? e.which : window.event.keyCode;
return pK != 13;
}
document.onkeypress = kH;
if (document.layers) document.captureEvents(Event.KEYPRESS);
</script>

you want to retrun a Tab, but to whom? This example script will disable the
enter key simply be looking for the keyCode (which is something like the
ASCII code).

Maybe you should ask what you do instead?!
Dec 5 '06 #3
Morten,

Good morning!

To explain the ?, look at:
http://www.c-point.com/javascript_tu...onditional.htm

Basically the ? is an operator that does a quick if then else for you.
so the line
var pK = e ? e.which : window.event.keyCode

is saying that if e is true, then set pK = e.which, which means that
the user is using Netscape/Firefox and if e is false, set pK to
window.event.keyCode , which means that the user is using IE.

This is another way of doing the same:

if(window.event) // IE
{
pK = e.keyCode
}
else if(e.which) // Netscape/Firefox/Opera
{
pK= e.which
}

!= means not equal to

Hope this is of some help,
Kathryn

Morten Snedker wrote:
On Tue, 5 Dec 2006 15:07:54 +0100, "Michael Schwarz"
<no****@schwarz-interactive.dewrote:

I wish to move to the next field in the tab-index. I reckon it is
something like nextfield.focus - but still, I don't know where to put
it.

I guess what I'm really missing is a Javascript Beginners Guide. :-)

But till then? ;-)
Instead of doing nothing I'd like to return a Tab-character, if Enter
occurs:

<script language="javascript" type="text/javascript" >
//disable enter-key
function kH(e) {
var pK = e ? e.which : window.event.keyCode;
return pK != 13;
}
document.onkeypress = kH;
if (document.layers) document.captureEvents(Event.KEYPRESS);
</script>
you want to retrun a Tab, but to whom? This example script will disable the
enter key simply be looking for the keyCode (which is something like the
ASCII code).

Maybe you should ask what you do instead?!
Dec 5 '06 #4
Hi,

kbutterly wrote:
Morten,

Good morning!

To explain the ?, look at:
http://www.c-point.com/javascript_tu...onditional.htm

Basically the ? is an operator that does a quick if then else for you.
so the line
var pK = e ? e.which : window.event.keyCode

is saying that if e is true, then set pK = e.which, which means that
Actually, this works because for JavaScript, if an object is null, it
can be tested against false. If it is not null, it can be tested against
true. So the line above actually means "if e is not null, assign e.which
to pK, or else assign window.event.keyCode. This is to avoid a null
reference exception, should e be null.

Note that the code above is not 100% safe, because window.event doesn't
get tested against null. Additionally, maybe e.which or
window.event.keyCode are undefined.

HTH,
Laurent
--
Laurent Bugnion, GalaSoft
Software engineering: http://www.galasoft-LB.ch
PhotoAlbum: http://www.galasoft-LB.ch/pictures
Support children in Calcutta: http://www.calcutta-espoir.ch
Dec 5 '06 #5
Hi Morten,

I wish to move to the next field in the tab-index. I reckon it is
something like nextfield.focus - but still, I don't know where to put
it.
the only thing you can do is to call the .focus() method of the next
control:

<input type="text" id="field1"
onkeypress="if(window.event.keyCode==13)document.g etElementById('field2').focus();">

<input type="text" id="field2">
I guess what I'm really missing is a Javascript Beginners Guide. :-)
;)
--
Best regards | Schöne Grüße
Michael

Microsoft MVP - Most Valuable Professional
Microsoft MCAD - Certified Application Developer

http://weblogs.asp.net/mschwarz/
http://www.ajaxpro.info/
Dec 5 '06 #6

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

Similar topics

2
2051
by: J. Nielsen | last post by:
I'm not a programmer and I don't have the time and energy to start learning right now So I need some help. Let's say I have made an HTML Table (consisting of three columns and six rows). In each...
7
8677
by: Mike | last post by:
I've been trying for the past week to put a simple code together. I have done a LOT of searching, found scripts showing the functions I would like to use, however when I mix them it all goes wrong,...
2
2178
by: TeknoCat | last post by:
Hey everyone, I may be repeating myself here, but if someone sent a reply then I missed it, and I can't get Outlook Express to download any messages more than 2 days old. Anyway, I'm having a...
11
1535
by: Jack | last post by:
I have a asp form where among others there are few text boxes and one check box. The checkbox is to indicate whether the entry is final. The checkbox is attahced to a field in table of type...
4
5207
by: E | last post by:
I am having trouble with setTimeout working on a second call to the setTimeout function from a second page which is an html page. Here is the scenario. I have a web page and onload it calls a...
32
2474
by: Tom Cole | last post by:
I bet 50% of the posts I've read lately have had at least one bad thing to say about every website or book dedicated to javascript. There are clearly a few posters (you know who you are) who...
6
2378
by: mrtaka79 | last post by:
Okay, first of all, I'm a complete noob, so go easy on me. I have this code that works perfectly for me. The only thing I want to add is to randomize the pictures/links that show up. Can anyone...
0
5518
by: gunimpi | last post by:
http://www.vbforums.com/showthread.php?p=2745431#post2745431 ******************************************************** VB6 OR VBA & Webbrowser DOM Tiny $50 Mini Project Programmer help wanted...
18
1865
by: Tom Cole | last post by:
I'm working on a small Ajax request library to simplify some tasks that I will be taking on shortly. For the most part everything works fine, however I seem to have some issues when running two...
0
7207
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
7357
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...
1
7012
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7468
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
5598
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,...
0
4690
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
1522
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 ...
1
748
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
402
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.