Keypress event

Y

yzzzzz

Hi,

<input type="text" onkeypress="alert(this.value)">

This doesn't work, it is always 1 character missing because the event
triggers *before* the character is inserted into the text box. How can I
get the entire string, including the last character?
(only needs to work with Mozilla or NN7)

Thanks.
 
E

Evertjan.

yzzzzz wrote on 13 jul 2003 in comp.lang.javascript:
<input type="text" onkeypress="alert(this.value)">

This doesn't work, it is always 1 character missing because the event
triggers *before* the character is inserted into the text box. How can I
get the entire string, including the last character?
(only needs to work with Mozilla or NN7)

onkeyup= ?
 
Y

yzzzzz

Scripsit "Evertjan.":
yzzzzz wrote on 13 jul 2003 in comp.lang.javascript:


onkeyup= ?

No!!
I think the answer is something like onchange, but that only gets
triggered onblur in Mozilla...
 
G

Grant Wagner

yzzzzz said:
Scripsit "Evertjan.":


No!!
I think the answer is something like onchange, but that only gets
triggered onblur in Mozilla...

What do you mean, no?

<form name="myForm">
<input type="text" name="test" onkeyup="alert(this.value);" />
</form>

Tested and alerts the entire content of the input each time a key is released
in IE6SP1, Mozilla 1.5a, Netscape 4.78 and Opera 7.11.

Note that in Mozilla, the backspace key causes a keyup event, but not in IE,
so when the user backspaces in the input, you won't know about the content of
the input until they press another character or tab out (at which point you
could test the content in the onblur event).

--
| Grant Wagner <[email protected]>

* Client-side Javascript and Netscape 4 DOM Reference available at:
*
http://devedge.netscape.com/library/manuals/2000/javascript/1.3/reference/frames.html

* Internet Explorer DOM Reference available at:
*
http://msdn.microsoft.com/workshop/author/dhtml/reference/dhtml_reference_entry.asp

* Netscape 6/7 DOM Reference available at:
* http://www.mozilla.org/docs/dom/domref/
* Tips for upgrading JavaScript for Netscape 6/7 and Mozilla
* http://www.mozilla.org/docs/web-developer/upgrade_2.html
 
E

Evertjan.

Grant Wagner wrote on 14 jul 2003 in comp.lang.javascript:
What do you mean, no?

<form name="myForm">
<input type="text" name="test" onkeyup="alert(this.value);" />
</form>

Tested and alerts the entire content of the input each time a key is
released in IE6SP1, Mozilla 1.5a, Netscape 4.78 and Opera 7.11.

Thanks. I usually do not follow up those unsubstanciated "no"s,
for who knows ;-)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,076
Messages
2,570,565
Members
47,200
Latest member
Vanessa98N

Latest Threads

Top