I know that some people, myself included, say that you’re not supposed to use innerHTML.
And yet for expediency’s sake, I find myself using innerHTML.
Problem
I’ve got an AJAX request to a JSP page which in turn performs an XSL transform on an XML file and returns a bunch of HTML <option> elements that JavaScript inserts into an existing <select> element using innerHTML.
Firefox does it fine, as you’d expect, but IE wasn’t playing nice. The resultant markup was broken, with a missing first opening <option> tag, and some random empty <option> element on the end.
In short, nothing showed up.
Solution
So I turned to google and found: BUG: Internet Explorer Fails to Set the innerHTML Property of the Select Object.
Thanks Microsoft, you just make it so easy. Not even.
I think the best solution here is to do it properly, and change my JSP to return a JSON object or something, and use createElement instead. I know innerHTML is faster, but it’s kinda not proper.
Charts and graphs and stuff
Monday, December 10th, 2007It’s funny how things come in droves.
A good friend of mine has, over the years, written a few applications that require graphing. He has written them as VB applications and when I’ve suggested he make them as web-apps, one of his fairly valid objections is that it would be tricky to create good-looking graphs with dynamic data.
Google’s Charting API
So just this morning, the Barnacle drew my attention to Google’s new Charting API (Read the Developers’ Guide). It takes some query string parameters and returns your chart as an image.
Check it out:
Now that’s pretty cool, isn’t it?
Although I think the data encoding, while clever, seems a little quirky.
Flot for jQuery
And so having spotted that this morning, I’m stumbling around the net this evening and discover Flot, a charting plug-in for jQuery. This is teh awesome; just check out the examples, especially the zoom!
So, while you’re waiting for other browsers to support SVG, here’s a veritable choice of quality charting goodness to satisfy the most particular of needs.
Posted in Coding, Commentary, JavaScript | 1 Comment »