Adventures with Javascript

gav on 2002-11-23T17:44:47

I have this love-hate relationship with javascript. You can use it to do some pretty nifty things that make both the client happy. On the down side there are major issues over different browsers and different platforms. The W3C have done a lot on this front, the DOM is pretty easy to work with (though I've always considered DOM to be a bit wordy to use, it probably is more at home for Java people than Perl people).

A lot of my work involves working with Yahoo Stores and one of the disadvantages of the platform is that you have very little control over the cart pages. I'm put javascript to work doing everything from working out the subtotal and popping up different windows depending on the amount, to hiding controls, changing the wording of text, and recently changing all the quantity boxes to text so that the user can't change them.

The thing that makes it possible is Mozilla's javascript console and debugger (Venkman). The console actually gives useful error messages and correct line numbers, while IE likes to complain about an "object expected" at line 1 character 1. Venkman can be invaluable when it comes to looking at the javascript output from a cgi script (I've done some crazy stuff where you have javascript that writes a script tag that calls a perl cgi script which writes it from a database query, but I'm trying to repress those memories).

Anyway, the reason for this overly verbose rant-of-sorts is that I've spend an hour and a half this morning fixing some javascript so it works on IE 5 for the Mac. The problem was that the cellpadding for a popout table was accidently set to null by some javascript. This was fine on every browser and platform I tested on, as you'd expect as null is 0 in a numeric context, but not Mac IE 5. This gave a "invalid procedure call" error on a completely random line number. Setting it to 0 fixed that. Arrgh.