problem fetching value of <input type="text"...

S

Smugsboy

Got a problem here, hope someone can help.
I want to fetch edit box's (<input type="text"...) value string upon
change. What I do is I attach handler to the onkeypress event. I have
two issues with this:

1. When the onkeypress handler executes I do not get the latest char
that was pressed (if the 't' char for "cat" was pressed I'll only get
"ca"), this is true for both IE & Firefox. Is there any solution to
this ? I need a solution that will work both on IE & Firefox.

2. Is there a more through event I should attach to ? because using
only the onkeypress I miss copy-paste operations.

Thanks,
 
S

Steve Pugh

Smugsboy said:
Got a problem here, hope someone can help.
I want to fetch edit box's (<input type="text"...) value string upon
change. What I do is I attach handler to the onkeypress event. I have
two issues with this:

1. When the onkeypress handler executes I do not get the latest char
that was pressed (if the 't' char for "cat" was pressed I'll only get
"ca"), this is true for both IE & Firefox. Is there any solution to
this ? I need a solution that will work both on IE & Firefox.

Depends on the order of events I suppose. Looks like the keypress event
takes place before the content of the input is changed. the onkeypress
event isn't really the best tool for the job...
2. Is there a more through event I should attach to ? because using
only the onkeypress I miss copy-paste operations.

onchange

Steve
 
S

Smugsboy

onchange captures focus change and not not value change in <input
type="text"
So it doesn't help me much.

Thanks,
 
J

Jonathan N. Little

Steve said:
Depends on the order of events I suppose. Looks like the keypress event
takes place before the content of the input is changed. the onkeypress
event isn't really the best tool for the job...




onchange

'onchange' with fire after user presses 'enter' or leaves the field as
with an 'onblur'. Sounds like the behavior that the OP seeks is
'onkeyup' which fires AFTER the key is pressed. My understanding is
'onkeyup' has checkered support...others may have more info on the subject.
 
S

Smugsboy

Jonhathan,
What do you mean by "checkered support" ?
If I use the onkeyup, will it respond for every char input (even if I
press a long keystroke which translates to several input characters) ?
Are the event the same in IE/FF?

Thanks,
 
J

Jonathan N. Little

Smugsboy said:
Jonhathan,

Hi Smugsboy,

Firstly if you peruse the newsgroup you will notice that TOP POSTING is
frowned upon, write responses below quoted material.
What do you mean by "checkered support" ?

onkeyup should be supported in modern browsers, was an issue in the past.
If I use the onkeyup, will it respond for every char input (even if I
press a long keystroke which translates to several input characters) ?

Every time the key is released the event fires,

'long keystroke' ?? Do you mean where you hold the key down and the
'type-o-matic' repeat on character occurs? Again it fires when the key
go up.

Demo may help explain:

<html>
<head>
<title>TestBed</title>
<script type="text/javascript">
function test(ff){
var f=ff.form;
f.myout.value=ff.value;
}
</script>
</head>
<body>
<form>
in <input type="text" size="30" name="myin" onkeyup="test(this)"><br>
out <input type="text" size="30" name="myout"><br>
</form>
</body>
Are the event the same in IE/FF?
<snip>
 

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

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,012
Latest member
RoxanneDzm

Latest Threads

Top