Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > Event question

Reply
Thread Tools

Event question

 
 
sheldonlg
Guest
Posts: n/a
 
      07-20-2011
i have a control where if I type in a few characters it brings up a
select list. To illustrate, suppose I type in 123. It would then bring
up a select list of 12301, 12302, etc.

Supposing then I select one of them, say 12305. The control then shows
12305. I also have an onChange event on that control. When that fires
it looks for the value that is currently in that control. What it finds
is not 12305, but 123.

I am wondering is there is some other event that I can use that will
fire when the value changes, but after it has been set to the new value.
That is what I thought that onChange did, but apparently not.

--
Shelly
 
Reply With Quote
 
 
 
 
sheldonlg
Guest
Posts: n/a
 
      07-20-2011
On 7/20/2011 11:59 AM, sheldonlg wrote:
> i have a control where if I type in a few characters it brings up a
> select list. To illustrate, suppose I type in 123. It would then bring
> up a select list of 12301, 12302, etc.
>
> Supposing then I select one of them, say 12305. The control then shows
> 12305. I also have an onChange event on that control. When that fires it
> looks for the value that is currently in that control. What it finds is
> not 12305, but 123.
>
> I am wondering is there is some other event that I can use that will
> fire when the value changes, but after it has been set to the new value.
> That is what I thought that onChange did, but apparently not.
>


Answered my own question. It is the onSelect.

--
Shelly
 
Reply With Quote
 
 
 
 
Thomas 'PointedEars' Lahn
Guest
Posts: n/a
 
      07-20-2011
sheldonlg wrote:

> sheldonlg wrote:
>> i have a control where if I type in a few characters it brings up a
>> select list. To illustrate, suppose I type in 123. It would then bring
>> up a select list of 12301, 12302, etc.
>>
>> Supposing then I select one of them, say 12305. The control then shows
>> 12305. I also have an onChange event on that control. When that fires it
>> looks for the value that is currently in that control. What it finds is
>> not 12305, but 123.
>>
>> I am wondering is there is some other event that I can use that will
>> fire when the value changes, but after it has been set to the new value.
>> That is what I thought that onChange did, but apparently not.

>
> Answered my own question. It is the onSelect.


`onchange' and `onselect' are event-_handlers_. The corresponding events
are `change' and `select'. MSDN Library has that mostly wrong for
historical reasons.

The `change' event occurs when a control loses the input focus and the
control's value has changed while it had the input focus. The `select'
event occurs "when the user selects some *text*"¹.

Since there is no `onChange' or `onSelect' property, you must be using
event-handler attributes. Be sure to declare HTML5 then, because there is
no `onselect' attribute for the `in Valid HTML 4.01.

However, even HTML5 does not redefine the `select' event, which indicates
that you are using an error-prone approach. You should add listeners for
mouse and keyboard events instead: `click' or `mousedown', `keyup' and
`keypress'.


PointedEars
___________
¹ <http://www.w3.org/TR/DOM-Level-3-Events/#event-type-select>
--
Anyone who slaps a 'this page is best viewed with Browser X' label on
a Web page appears to be yearning for the bad old days, before the Web,
when you had very little chance of reading a document written on another
computer, another word processor, or another network. -- Tim Berners-Lee
 
Reply With Quote
 
Thomas 'PointedEars' Lahn
Guest
Posts: n/a
 
      07-20-2011
sheldonlg wrote:

> sheldonlg wrote:
>> i have a control where if I type in a few characters it brings up a
>> select list. To illustrate, suppose I type in 123. It would then bring
>> up a select list of 12301, 12302, etc.
>>
>> Supposing then I select one of them, say 12305. The control then shows
>> 12305. I also have an onChange event on that control. When that fires it
>> looks for the value that is currently in that control. What it finds is
>> not 12305, but 123.
>>
>> I am wondering is there is some other event that I can use that will
>> fire when the value changes, but after it has been set to the new value.
>> That is what I thought that onChange did, but apparently not.

>
> Answered my own question. It is the onSelect.


`onchange' and `onselect' are event-_handlers_. The corresponding events
are `change' and `select'. MSDN Library has that mostly wrong for
historical reasons.

The `change' event occurs when a control loses the input focus and the
control's value has changed while it had the input focus. The `select'
event occurs "when the user selects some *text*"¹.

Since there is no `onChange' or `onSelect' property, you must be using
event-handler attributes. Be sure to declare HTML5 then, because there is
no `onselect' attribute for the SELECT element in Valid HTML 4.01.

However, even HTML5 does not redefine the `select' event, which indicates
that you are using an error-prone approach. You should add listeners for
mouse and keyboard events instead: `click' or `mousedown', `keyup' and
`keypress'.


PointedEars
___________
¹ <http://www.w3.org/TR/DOM-Level-3-Events/#event-type-select>
--
Anyone who slaps a 'this page is best viewed with Browser X' label on
a Web page appears to be yearning for the bad old days, before the Web,
when you had very little chance of reading a document written on another
computer, another word processor, or another network. -- Tim Berners-Lee
 
Reply With Quote
 
sheldonlg
Guest
Posts: n/a
 
      07-20-2011
On 7/20/2011 4:27 PM, Thomas 'PointedEars' Lahn wrote:
> sheldonlg wrote:
>
>> sheldonlg wrote:
>>> i have a control where if I type in a few characters it brings up a
>>> select list. To illustrate, suppose I type in 123. It would then bring
>>> up a select list of 12301, 12302, etc.
>>>
>>> Supposing then I select one of them, say 12305. The control then shows
>>> 12305. I also have an onChange event on that control. When that fires it
>>> looks for the value that is currently in that control. What it finds is
>>> not 12305, but 123.
>>>
>>> I am wondering is there is some other event that I can use that will
>>> fire when the value changes, but after it has been set to the new value.
>>> That is what I thought that onChange did, but apparently not.

>>
>> Answered my own question. It is the onSelect.

>
> `onchange' and `onselect' are event-_handlers_. The corresponding events
> are `change' and `select'. MSDN Library has that mostly wrong for
> historical reasons.
>
> The `change' event occurs when a control loses the input focus and the
> control's value has changed while it had the input focus. The `select'
> event occurs "when the user selects some *text*"¹.
>
> Since there is no `onChange' or `onSelect' property, you must be using
> event-handler attributes. Be sure to declare HTML5 then, because there is
> no `onselect' attribute for the SELECT element in Valid HTML 4.01.
>
> However, even HTML5 does not redefine the `select' event, which indicates
> that you are using an error-prone approach. You should add listeners for
> mouse and keyboard events instead: `click' or `mousedown', `keyup' and
> `keypress'.
>
>
> PointedEars
> ___________
> ¹<http://www.w3.org/TR/DOM-Level-3-Events/#event-type-select>


Sorry to be sloppy with my terminology, but I;m glad you got the meaning.

--
Shelly
 
Reply With Quote
 
RobG
Guest
Posts: n/a
 
      07-21-2011
On Jul 21, 2:02*am, sheldonlg <(E-Mail Removed)> wrote:
[...]
> Answered my own question. *It is the onSelect.


Have you discovered that IE dispatches a select event each time the
selection changes *while* the user is still in the act of selecting
the text?

I have found that behaviour to make the use of the select event
virtually useless, much better to wait for some other event (mouseup,
keyup, whatever suits) as Thomas suggested, then see if anything has
been selected.

The bubbling of select events is also different across browsers to the
point of being unusable, e.g. setting a listener on the body will
respond only to selections in input and textarea elements in Firefox
and others, but only in the document itself in IE. Such opposing
behaviour makes event delegation difficult.

The result is that you must put a listener on each element you wish to
monitor (if you choose to persist with using select).


--
Rob
 
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
image button click event fires before click event of button Purvi T ASP .Net 0 10-19-2004 06:19 AM
Catching a RequiredFiled Validator event in PageLoad or some other event? Lars Netzel ASP .Net 3 07-22-2004 10:48 PM
Button.Init? how Do I know if click event has been fired? TextBox.TextChanged event before Button.Click in a CompositeCustomControl. jorge ASP .Net 2 05-25-2004 11:45 PM
PreRender Event occurs immediatley after Load event =?Utf-8?B?QWxpcmV6YSBaaWFp?= ASP .Net 1 02-09-2004 10:19 AM
Event On Form From Control Event Dave Wurtz ASP .Net 1 12-09-2003 10:37 PM



Advertisments