Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > HTML > problem fetching value of <input type="text"...

Reply
Thread Tools

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

 
 
Smugsboy
Guest
Posts: n/a
 
      11-30-2005
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,

 
Reply With Quote
 
 
 
 
Steve Pugh
Guest
Posts: n/a
 
      11-30-2005
Smugsboy wrote:
> 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

 
Reply With Quote
 
 
 
 
Smugsboy
Guest
Posts: n/a
 
      11-30-2005
onchange captures focus change and not not value change in <input
type="text"
So it doesn't help me much.

Thanks,

 
Reply With Quote
 
Jonathan N. Little
Guest
Posts: n/a
 
      11-30-2005
Steve Pugh wrote:
> Smugsboy wrote:
>
>>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


'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.


--
Take care,

Jonathan
-------------------
LITTLE WORKS STUDIO
http://www.LittleWorksStudio.com
 
Reply With Quote
 
Smugsboy
Guest
Posts: n/a
 
      11-30-2005
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,

Jonathan N. Little wrote:
> Steve Pugh wrote:
> > Smugsboy wrote:
> >
> >>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

>
> '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.
>
>
> --
> Take care,
>
> Jonathan
> -------------------
> LITTLE WORKS STUDIO
> http://www.LittleWorksStudio.com


 
Reply With Quote
 
Jonathan N. Little
Guest
Posts: n/a
 
      11-30-2005
Smugsboy wrote:
> 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>
</html>


> Are the event the same in IE/FF?

<snip>






--
Take care,

Jonathan
-------------------
LITTLE WORKS STUDIO
http://www.LittleWorksStudio.com
 
Reply With Quote
 
Hywel Jenkins
Guest
Posts: n/a
 
      11-30-2005
In article < .com>,
says...
> onchange captures focus change


It doesn't.

> and not not value change in <input type="text"


Yes, it does. That's why it's called "onchange".

Quote the post you're replying, too.

--

Hywel
http://kibo.org.uk/
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Error Fetching Custom Attribute Value from HtmlSelect mirlisa ASP .Net 2 08-29-2006 03:49 PM
Big problem fetching members from dynamically loaded module Philippe C. Martin Python 8 06-26-2005 02:56 PM
Problem in fetching the details in Datagrid Raghuram ASP .Net 0 05-07-2005 09:56 AM
problem fetching *only one* value. Nitin Perl Misc 2 09-19-2004 04:06 AM
Problem in Fetching Session Variable =?Utf-8?B?UGhhbmlkaGFy?= ASP .Net 1 04-01-2004 05:24 PM



Advertisments