Monday, November 12, 2007

DOM elements case sensitive in FireFox, not IE

I like a robust application, and case (in)sensitivity is often a good candidate, i.e. where possible, let your users type Answer, answer, ANSWER or ANswer. As long as you know the answer, does it matter what case they use?

Sometimes it can get in the way. A couple of times I have stumbled on this one. Here is some Ajax style Javascript I was using in a page today. It worked in IE, but not in FireFox.

function updatePage() {
  if (request.readystate != 4) {
    return;
  }
  if (request.status != 200) {
    alert("Error with request.status [" + request.status + "].");
  }
  var customerAddress = request.responsetext;
  document.getElementById("address").value = customerAddress;
}

It was my sloppy typing of course, but I found it to be a hard mistake to track down, and annoying because I thought the code was working fine until I opened it in FireFox.

When I used readystate instead of readyState in FireFox, the function always returned.

When I used responsetext instead of responseText in FireFox, I would always see "undefined" in my address field.

Ultimately, this is one instance where I do wish IE was case insensitive, so it would be a lot harder to write code that works in one place and not the other. (Of course, you might argue that FireFox should be case insensitive... I won't, but you might. I like my scripting to be a little more precise.)

No comments: