jump to navigation

NOTE: The spam filter is being unusually aggressive. If you comment does not immediately appear, it has simply been placed in moderation and I will approve it as quickly as possible. Thank you for your patience.

"Murphy was an optimist!"

I’m done with document.getElementById March 29, 2009 1:47 pm

Posted by Doug McCaughan in : JavaScript, jQuery, Programming, Technology
, trackback

I’m working on a project that has compatibility with Internet Explorer 6 as a major requirement. This means all appearances, all Ajaxy functionality, every aspect of the web application should look and perform in IE6 just as it would in Firefox, Chrome, IE7, IE8, and Safari. One of my favorite pieces of code is "document.getElementById()" but special cases have to be considered for IE 6. As an example, you can use getElementById to change the value of a hidden form element:

<input type="hidden" id="foo" name="foo" value="default value">
<input type="submit" id="goBtn" name="goBtn" value="Process..." onclick="document.getElementById('foo').value='anothervalue';">

That code will not always work. jQuery comes to the rescue! Rather than write lines and lines of additional code for browser testing and coding for a special case, we can simply replace "document.getElementById(‘foo’).value=’anothervalue’;" with "$(‘#foo’).val(‘anothervalue’);" and the code will work.

<input type="hidden" id="foo" name="foo" value="default value">
<input type="submit" id="goBtn" name="goBtn" value="Process..." onclick="$('#foo').val('anothervalue');">

I cannot sing jQuery’s praises enough!

Comments after advertisement


1. Danny - March 29, 2009

Your client seriously wants an outmoded, security-risk-bearing browser to be supported? It’s about to be two versions back from currency. Its user share is 17% and dropping a percent a month at present, according to W3C schools.

And, again, it’s a nasty nasty security risk.

But then, you know that. I just thought I’d rant at your client for you.

2. Kae Verens - March 30, 2009

17% is almost 1 in 5. Much as I’d agree that IE6 is obsolete and should be shunned, if 1 in 5 of your clients are still using it, it must be supported.

Over a year ago, I complained that a certain local government department was reading its webpages in IE6 and asked why they were not being upgraded to IE7. I was told “for security reasons, we don’t allow people to change their software”. Personally, I would consider “security reasons” to be a /perfect/ reason to upgrade…

but yeah, jQuery ftw! (I’m writing a book on it, atm 😉 )

3. Danny - March 30, 2009

Those clients deserve a reasonably functional web page. The definition of “reasonably functional” is the issue here. Do they need “all appearances, Ajaxy functionality,” etc.? Do they need you to shoehorn into IE6 functions that did not exist or were not mature when it was a current MicroSoft product?

There are two reasonable choices here: scale back the functionality of the site overall or allow a scaled-back set of functions for users of obsolete browsers. “Full support” is not tenable as Doug describes it here.