Javascript gripe # 2

The add() function of the html select object functions totally different in IE and Firefox.

It is defined as :

Where option is an option object. Before is the tricky part.

In firefox, the second parameter is supposed to be a reference to the option object you want to place your new object in front of. In IE, it is the index to the object you want to remove.

These are fundamentally different.

In FF, you have to do this:

in IE, you do this:

Apparently, Firefox is correct according to the DOM specifications:
void add(in HTMLElement element, in HTMLElement before) raises(DOMException);
void remove(in long index);

But tell me, why does the add method use an object while the remove uses an index???. The standard is messed up, not IE.


Javascript tip

I was having the most unusual problem in a function that used a for loop to find selected items in a html select list. My iterator variable “i” was for some reasen ending up with a value higher than the for loop would allow.

As it turns out, if you declare a variable without using the “var” keyword, that variable has global scope.

Case in point:

function pressRemove() {
  fromBox = selBox;
  toBox = allBox;
  for (i=fromBox.length-1;i>=0;i--) {
    if (fromBox.options[i].selected) {

The function addOpt includes it’s own for loop, also using a variable named i. That inner for loop was overwriting the value in this for loop!

  for (var i=fromBox.length-1;i>=0;i--) {

By changing all the for loops to declare their variables, the problem was solved. Personally, I think that is a really stupid “feature”, but since both IE and Firefox do it, it is expected.

Mac vs PC?

Apple is right, 100%. OS X is better than windows hands down. Expecially better than Vista.

Mac computers, on the other hand, are far inferior in value, performance, features, expandability and future-proof-ness.

All of the consumer Mac machines are either one-piece or extremely compact. Can you upgrade? No, Apple makes more money if you buy another EXTREMELY overpriced computer if your old one get too slow.

Every one of Apple’s computers were designed with form overshadowing function. They are pretty, and stylish, but they lack the things that really matter.

If OS X was available on hardware that I could control, upgrade and modify at will, (e.g. a PC) I would switch immediately. Apple could destroy Windows by doing this, and at this point it would be trivial for them to do so (research the Hackintosh…). They will not, though. Apple is well aware that their lucrative hardware sales are driven by the superior operating system, and that nobody in their right mind would pay $2,000 for a Mac when they could get the same thing for $750 in a PC.

I want to create something!

Sometimes I get it the mood to make something beautiful.

Like right now. I want to make music. Composing it would be fine, or performing. But guess what? I cannot do either.

I can hear something, and tell that it is beautiful. I am very good at analyzing music… but I just can’t create it! Nor can I play it very well. My sister has amazing piano skill she takes for granted. A song I struggled with off and on for a month to get one hand at a time slowly… she could sight read both hand at near full speed.
With practice I can get better at a song, but not at playing. When I mess up, I cannot gracefully recover.

It is similar with visual art. I wish I could express the imagery in my mind on paper (or some other format) but my hands are incapable. I can only draw well when I trace, and even then it looks like the work of a child.

I am left-handed. Doesn’t that mean I’m supposed to be more creative?

I often argue that my art is in writing code. I express my creativity through programming. But this is something very few people can appreciate – most would rather not even try.
Occasionally I can be creative with words, but I tend not to write about beautiful things.

It is a stange feeling, the desire to create. It is even more strange to be unable to.