Posts Tagged ‘dom’

Damned DOM (1)

Monday, June 22nd, 2009

When I wanted to react to any changes to a input textbox immediately, my first instrinct was to use onChange. onChange, however, is called when the input loses focus. onKeyPress then? Isn’t called on backspaces. onKeyDown, maybe? It does get called, but the effect of the keystroke isn’t yet applied, for the return value determines whether it that is done in the first place. (Same story for onKeyPress by the way.) onKeyUp does work a bit, except if someone is holding down a single key, for a while.

The solution: hook onKeyUp and use setTimeout with a timeout of 0. Yugh. I hate DOM.

Big Fat Disclaimer: I actually tested this only on one browser.

Stupid IE (2)

Sunday, September 2nd, 2007

To create a multiple select-box with javascript you need a very ugly hack in IE.

if (navigator.appName.match(/Internet Explorer/)) {
	fsel = document.createElement(\'<SELECT MULTIPLE>\');
} else {
	fsel = document.createElement(\'select\');
	fsel.multiple = true;
}