FireFox: event handling problem

Discussion in 'Javascript' started by StepanM, Jan 17, 2008.

  1. StepanM

    StepanM Guest

    Problem with event handling in FireFox. I have two controls on HTML
    page: ListBox and TextBox (<select> and <input>). Both controls have
    event "onchange" and functions for this event (e.g. select_onchange
    and text_onchage). If I select item in ListBox, than I enter text in
    TextBox, and than I finally select other item in ListBox, then both
    events fires simultaneously (it can be checked up, if in both
    functions write a corresponding "alert", both alerts appear
    simultaneously). How to solve this problem?
    It is very important.

    Thanks
     
    StepanM, Jan 17, 2008
    #1
    1. Advertising

  2. StepanM

    David Mark Guest

    On Jan 17, 7:49 am, StepanM <> wrote:
    > Problem with event handling in FireFox. I have two controls on HTML
    > page: ListBox and TextBox (<select> and <input>). Both controls have
    > event "onchange" and functions for this event (e.g. select_onchange
    > and text_onchage). If I select item in ListBox, than I enter text in
    > TextBox, and than I finally select other item in ListBox, then both
    > events fires simultaneously (it can be checked up, if in both
    > functions write a corresponding "alert", both alerts appear
    > simultaneously). How to solve this problem?
    > It is very important.
    >


    It is very important to realize that displaying an alert after a
    change or blur event makes for an annoying and error-prone interface
    (so don't do it.) Use the containing form's submit event for
    validation.
     
    David Mark, Jan 17, 2008
    #2
    1. Advertising

  3. StepanM wrote:
    > Problem with event handling in FireFox. I have two controls on HTML
    > page: ListBox and TextBox (<select> and <input>). Both controls have
    > event "onchange" and functions for this event (e.g. select_onchange
    > and text_onchage). If I select item in ListBox, than I enter text in
    > TextBox, and than I finally select other item in ListBox, then both
    > events fires simultaneously (it can be checked up, if in both
    > functions write a corresponding "alert", both alerts appear
    > simultaneously). How to solve this problem?
    > It is very important.
    >


    I have noted that..the onchange() doesn't trigger until you change
    focus to another bit of the screen in some browsers in some situations.

    I think I fixed it once by using onmouseout() and then checking which
    option was selected, and if it wasn't already selected, triggering the
    script I wanted.



    > Thanks
     
    The Natural Philosopher, Jan 17, 2008
    #3
  4. StepanM

    David Mark Guest

    On Jan 17, 11:48 am, The Natural Philosopher <> wrote:
    > StepanM wrote:
    > > Problem with event handling in FireFox. I have two controls on HTML
    > > page: ListBox and TextBox (<select> and <input>). Both controls have
    > > event "onchange" and functions for this event (e.g. select_onchange
    > > and text_onchage). If I select item in ListBox, than I enter text in
    > > TextBox, and than I finally select other item in ListBox, then both
    > > events fires simultaneously (it can be checked up, if in both
    > > functions write a corresponding "alert", both alerts appear
    > > simultaneously). How to solve this problem?
    > > It is very important.

    >
    > I have noted that..the onchange()  doesn't trigger until you change
    > focus to another bit of the screen in some browsers in some situations.
    >
    > I think I fixed it once by using onmouseout() and then checking which
    > option was selected, and if it wasn't already selected, triggering the
    > script I wanted.
    >


    That would assume that a pointing device is in use. In any event, I
    wouldn't recommend such an approach.
     
    David Mark, Jan 17, 2008
    #4
  5. StepanM

    RobG Guest

    On Jan 17, 10:49 pm, StepanM <> wrote:
    > Problem with event handling in FireFox. I have two controls on HTML
    > page: ListBox and TextBox (<select> and <input>). Both controls have
    > event "onchange" and functions for this event (e.g. select_onchange
    > and text_onchage). If I select item in ListBox, than I enter text in
    > TextBox, and than I finally select other item in ListBox, then both
    > events fires simultaneously (it can be checked up, if in both
    > functions write a corresponding "alert", both alerts appear
    > simultaneously). How to solve this problem?
    > It is very important.


    Onchange can be difficult to program - it is supposed to fire when an
    element loses focus, but some browsers don't wait for that for some
    form controls while others do.

    I expect what is happening in your case is that when you click on the
    select the second time, that is when the text area loses focus and
    fires its onchange event. Displaying the alert probably causes the
    select to lose focus with perhaps a different option selected so it
    too fires its onchange event.

    You need to investigate using a different event for one or perhaps
    both controls. Without knowing what you are actually trying to do, a
    more precise solution can't be suggested.

    Do you have a small example you can post, along with a description of
    what you want to happen?


    --
    Rob
     
    RobG, Jan 18, 2008
    #5
    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. The Alchemist
    Replies:
    4
    Views:
    797
    Mircea Pleteriu
    Jun 23, 2004
  2. Mark Tarver
    Replies:
    22
    Views:
    1,384
    J Kenneth King
    Apr 26, 2009
  3. Peter
    Replies:
    34
    Views:
    2,022
    James Kanze
    Oct 17, 2009
  4. Iñaki Baz Castillo
    Replies:
    1
    Views:
    219
    Iñaki Baz Castillo
    Apr 15, 2008
  5. StepanM

    FireFox: event handling problem

    StepanM, Jan 18, 2008, in forum: Javascript
    Replies:
    0
    Views:
    119
    StepanM
    Jan 18, 2008
Loading...

Share This Page