Two problems:
The event is called change
, not onchange
. onchange
is the name of an HTML attribute and a DOM property.
You have to pass a function to addEventListener
, not a string.
So
fontsize.addEventListener('change', updateText, false);
should work.
It seems you are mixing inlineor traditional event handlers with advanced event handlers.
Equivalent inline event handler:
<select id="fontsize" onchange="updateText()">
or (don't do that):
fontsize.setAttribute('onchange', 'updateText()');
Unless you are only prototyping something, using inline event handlers is generally not a good idea, see below.
Equivalent traditional event handler:
fontsize.onchange = updateText;
Why is using event delegation model recommended over <select onchange="someMethod()">
This has nothing to do with event delegation. Event delegation is a concept independent from the way the event handlers are bound. For a practical reason not to use inline event handlers, see my answer here onclick="" vs event handler.
I also recommend to read the articles on quirksmode.org which in my opinion explain everything you need to know about event handlers.