Open Bug 297134 Opened 19 years ago Updated 3 years ago

Using setTimeout workaround for select() in onBlur event causes bizarre behaviour if Firefox loses and regains focus


(Core :: DOM: Events, defect, P5)

Windows XP





(Reporter:, Unassigned)


(Whiteboard: DUPEME)

User-Agent:       Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.8) Gecko/20050511 Firefox/1.0.4
Build Identifier: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.8) Gecko/20050511 Firefox/1.0.4

Using the following Javascript for validation appears to allow select() to work

function checkDate() {
  if (badInput) {
    alert("Bad input");
    setTimeout("document.getElementById('myDate').select();", 1);

<input type="text" name="myDate" id="myDate" onblur="checkDate();">

However, when I switch focus to another application and return to Firefox, the
alert has been raised again (as it should), click Ok to clear it, discover the
alert is raised a second time (shouldn't happen), click Ok to clear it, the
browser appears to be working normally but exhibits some bizarre behaviour.

Hopefully this information will help isolate the problem.


Reproducible: Always

Steps to Reproduce:
1. Use the following Javascript in a function called by onBlur event of a text
    alert("Bad input");
    setTimeout("document.getElementById('myDate').select();", 1);
2. The alert will raise and the element will focus and select correctly.
3. Click Ok to clear the alert but do not change the text in the input.
4. Switch focus to another application, then return to Firefox.
5. The alert will be raised again (as it should), click Ok to clear it.
6. The alert will be raised again (it shouldn't), click Ok to clear it.

Actual Results:  
1) None of the text inputs will receive focus (either by keyboard or mouse)
2) The address bar will not receive focus (either by keyboard or mouse)
3) Dropdowns (SELECT elements) will drop down once and display the OPTION values
but will not change to reflect the new value you select. The list will not drop
down again.
4) Links still work correctly.
5) When you navigate away from the problem page, then return by clicking a link,
these problems persist.

Expected Results:  
The alert should have only be raised once. After clearing it, all form elements
in the browser should have functioned normally.

At the very least, it seems that navigating away and returning to a fresh copy
of the page should have functioned properly.
Severity: critical → normal
Assignee: nobody → events
Component: General → DOM: Events
Product: Firefox → Core
QA Contact: general → ian
Version: unspecified → Trunk
Whiteboard: DUPEME
Brian, do you still see this bug with recent trunk builds?
keywords: javascript, AJAX, DWR, SELECT, OPTION, display, DOM


I have a similar problem trying to load the options for a select using AJAX and event handling.

Scenario: I have two selects that loads data with AJAX (with DWR package), the first one loads inconditinally but the second one loads when the previous select exits with an onBlur event (The first select has an onkeypress handler too)

The problem appears when I click to the second select.

The DOM information (document.getElemById...selectedIndex returns 0) is not syncronized with the presentation: I get an empty selection in the "select" but the popup shows 2 options.

I tried disabling the second select, then load the data and finally enable it but the same problem appeared.

Looking for similar bugs (61174) I tried setting the "size" attr. to "1" but it didn't displayed any option at all.

I'm sorry I didn't paste the browser info.

Mozilla/5.0 (Windows; U; Windows NT 5.1; es-ES; rv: Gecko/20060508 Firefox/
Sorry, I failed to reply to this earlier. Yes, I still see this same problem in Firefox 

The setTimeout workaround is no longer necessary to avoid an error, but the same problem occurs with the onBlur event after clicking to another application and returning to Firefox.
This bug isn't very prominent in searches for "onblur focus disable"; I found it by my first result, bug 53579.
keywords: onblur, focus, disable, text field, textfield, 

To enable form elements (including the GUI) again, bring another window (can be the Downloads one) into focus after dismissing the alerts, then come back to Firefox.
Assignee: events → nobody
QA Contact: ian → events

Bulk-downgrade of unassigned, untouched DOM/Storage bug's priority.

If you have reason to believe, this is wrong, please write a comment and ni :jstutte.

Severity: normal → S4
Priority: -- → P5
You need to log in before you can comment on or make changes to this bug.