Damon Cortesi's blog

Musings of an entrepreneur.

Javascript Compliance and Oddity

| Comments

Microsoft did a horrible thing for online standards when it allowed Internet Explorer (IE) to accept javascript code that wasn’t fully compliant. Sure, things are easier for developers…at first, until somebody wants to use a different browser.

For example, I ran into some code today that set the value of a text input in a form:


That’s pretty easy and intuitive, but it only works in IE. Want to get it to work elsewhere? Here’s the updated code:


whoa Notice two things:

  1. getElementsByName is plural, getElementByName does not work.
  2. Because you must use the plural, an array is returned and you have to reference the first value in the array by using [0]
Other than the plurality confusion, I would much rather sacrifice easy-to-write code for cross-browser compatibility!