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:
date_input.value=’10/07/2004’
That’s pretty easy and intuitive, but it only works in IE. Want to get it to work elsewhere? Here’s the updated code:
document.getElementsByName(‘date_input’)[0].value=’10/07/2004’
whoa Notice two things:
- getElementsByName is plural, getElementByName does not work.
- Because you must use the plural, an array is returned and you have to reference the first value in the array by using [0]