Are you expecting the JS to respond while the alert box is up? Is that
it? All this business about setting timeouts is absolutely the wrong
way to go about things. The window.alert box is a modal dialog; of
course nothing else will respond on your page while it's up, that's
what a modal dialog does.
Your sequence of events is like this:
1. You type into the box.
2. You click on the button.
3. The box loses focus; the focus has to be released by the box before
it can be applied to the button.
4. The box's onchange event fires
5. The modal alert dialog pops up.
6. Since the onchange event fired before the button onclick event
fired, the modal dialog suppressed the click event. Notice how the
button does not go down in this case.
Firefox saves the suppressed click event for later (after the first
alert is gone), while IE ignores it.
And as another poster said, this is not a problem if you do anything
except show a modal dialog.
Speaking of quirks mode (we weren't really, but I saw it in the URL
above), I've been reading about this but I can't understand how to be
compatible with both old browsers (quirks mode) and new browsers (via
the use of a DOCTYPE) without sprinkling my code with version checks
anyway. If I specify that I'm XHTML complaint, I still have to test for
old browsers and adjust my code accordingly. So is a DOCTYPE really
helping me if I have to use ugly browser testing code anyway?
Well, hehe, this has been the focus of much recent debate on this list.
It really depends on what your target audience is going to be. For
most generic, general-purpose web work, you can safely assume the
browsers you should care about are (in this rough order) IE6, Firefox,
IE7, Safari, Opera 9, and sometimes IE5. Anything else (IE4 or any
version of Netscape, for instance - the modern Netscape uses the
Mozilla engine which in turn is a phoenix reborn of the ancient NS's
ashes) is ancient and for most uses can be considered obsolete. So
most of that "feature testing" code, while good relevant technique for
browser incompatibility , is pretty irrelevant for testing *version* of
browsers. All modern browsers support DOM Level 0 and DOM Level 1, for
example. They're mixed on DOM Level 2 support, so this is where
feature testing comes in.
As for DOCTYPE, yes, you absolutely want to use a DOCTYPE. For most
purposes, you'll want a HTML 4.01 DOCTYPE as this ensures compatibility
with older browsers. If an old browser can't support the DOCTYPE, it
falls back to quirksmode. However, this shouldn't be an issue with any
browsers I listed above. XHTML can be faster and more consistently
rendered, but its full support is patchy and it gets converted into
HTML anyway by most browsers. The real reason DOCTYPEs are important,
though, has more to do with CSS rendering. IE behaves much more
predictably - that is, closer to the W3C standard - when using a valid
DOCTYPE.
I guess if I tried to add 1 it would have blown up unless I
had the parseInt.
Not exactly. In JS the following is true:
'1' + '1' == '1' + 1 == '11'
The + operator is used to concatenate strings, and anything that's not
a string, when added to a string, is automatically converted rather
than throwing an error.