Event question

Discussion in 'Javascript' started by sheldonlg, Jul 20, 2011.

  1. sheldonlg

    sheldonlg Guest

    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
    sheldonlg, Jul 20, 2011
    #1
    1. Advertising

  2. sheldonlg

    sheldonlg Guest

    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
    sheldonlg, Jul 20, 2011
    #2
    1. Advertising

  3. 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
    Thomas 'PointedEars' Lahn, Jul 20, 2011
    #3
  4. 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
    Thomas 'PointedEars' Lahn, Jul 20, 2011
    #4
  5. sheldonlg

    sheldonlg Guest

    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
    sheldonlg, Jul 21, 2011
    #5
  6. sheldonlg

    RobG Guest

    On Jul 21, 2:02 am, sheldonlg <> 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
    RobG, Jul 21, 2011
    #6
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Purvi T
    Replies:
    0
    Views:
    821
    Purvi T
    Oct 19, 2004
  2. Dave Wurtz

    Event On Form From Control Event

    Dave Wurtz, Dec 9, 2003, in forum: ASP .Net
    Replies:
    1
    Views:
    341
    Kevin Spencer
    Dec 9, 2003
  3. =?Utf-8?B?QWxpcmV6YSBaaWFp?=

    PreRender Event occurs immediatley after Load event

    =?Utf-8?B?QWxpcmV6YSBaaWFp?=, Feb 9, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    2,103
    Hans Kesting
    Feb 9, 2004
  4. jorge
    Replies:
    2
    Views:
    1,255
    jorge
    May 26, 2004
  5. Lars Netzel
    Replies:
    3
    Views:
    429
    Greg Burns
    Jul 22, 2004
Loading...

Share This Page