Newsgroup: it.comp.lang.javascript
Titolo: Pressione tasto Invio

Grazie in anticipo.
Il gestore degli eventi apposito dovrebbe essere onKeypress.
Ciao.
Roberto e Alessandro Abbate. Galileo
http://www.ipoint2000.net/galileo

In realtà quando premi <INVIO> viene generato l'evento onClick, come se ci
avvessi cliccato.
IE credo supporti onClick anche su <input type="text">, mentre NS credo solo
sui pulsanti.
CIAO :)
---
the fly on the net
webmaster di "the devil inside"
http://members.tripod.com/netfly
e-mail:
net...@netbusiness.it

Ho provato con onclick='ins.click()' (ins è il name del button).
Però se clicco sul text funziona correttamente, ma se scrivo e poi premo
invio non funziona (sembra quindi che la pressione del tasto invio non
generi onclick, quantomeno sui text (io lavoro con IE4)).
Mi parlano di onkeypress...qualcuno sa come gestirlo?
Grazie in anticipo.

Trovato!!!
 onkeypress='Javascript:if (event.keyCode==13) ins.click()'
Grazie comunque a tutti.

onKeyDown 
Executes JavaScript code when a KeyDown event occurs; that is, when the user depresses a key. Event handler for 
             document, Image, Link, Textarea
 
            Implemented in
             JavaScript 1.2
 
Syntax 
onKeyDown="handlerText"
Parameters 
handlerText
             JavaScript code or a call to a JavaScript function.
 
Event properties used 
Property  Description  
type
             Indicates the type of event. 
 
target
             Indicates the object to which the event was originally sent. 
 
layerX, layerY,pageX, pageY,screenX, screenY
             For an event over a window, these represent the cursor location at the time the event occurred. For an event over a form, they represent the position of the form element.
 
which
             Represents the ASCII value of the key pressed. To get the actual letter, number, or symbol of the pressed key, use the String.fromCharCode method. To set this property when the ASCII value is unknown, use the String.charCodeAt method. 
 
modifiers
             Contains the list of modifier keys held down when the event occurred.
 
Description 
A KeyDown event always occurs before a KeyPress event. If onKeyDown returns false, no KeyPress events occur. This prevents KeyPress events occurring due to the user holding down a key. 
Examples 
The following example uses the blockA function to evaluate characters entered from the keyboard in the textentry text box. If a user enters either "a" or "A", the function returns false and the text box does not display the value. 
<form name="main">   <input name="textentry" type=text size=10 maxlength=10></form><script>function blockA(e) {        var keyChar = String.fromCharCode(e.which);        if (keyChar == 'A' || keyChar == 'a')                return false;}document.main.textentry.onkeydown = blockA;</script>
In the function, the which property of the event assigns the ASCII value of the key the user presses to the keyChar variable. The if statement evaluates keyChar and returns false for the specified characters. 
See also 
event, onKeyPress, onKeyUp
------------------------------------------------------------------------------------------------------------------------
Il codice ASCII di INVIO è 13 (0x0D).
Per IE invece di "e" bisogna mettere "event"...
-- 
Cì@0
Ðarius. (
http://www.infotronica.it/darius/
)
-------------------------------------------------------