openguides; javascript

domm on 2005-04-06T10:24:32

This morning after boxing I met with Maks to solve an annyoing bug in vienna.openguides.org. The problem was that German Umlaute where mangled (sometimes). With some help from Kake we at least knew where to start looking, and after copious use of

print STDERR "..."
we tracked the problem down to a call to HTML::Parser.

After some looking at manpages etc I updated to the newest version of HTML::Parser and ... problem solved! Yay!

Oh, and yesterday I had to face the horros of JavaScript. One project needed some form fields prefilled depending on a value selected in a select box. After figureing out the JS code necessary (

var land=document.seas.staat.options[document.seas.staat.selectedIndex].value;
, ouch) I worte a small script that generated the 50 lines of JS code necessary to have an pseudo associatve array. 50 lines of boring
Vorwahl["AT"]="+43 ";


arrays

Juerd on 2005-04-06T21:55:32

All arrays in Javascript are associative. In fact, every object is an array and every array is an object. Methods are just array elements.

foo.bar and foo["bar"] are the same thing. foo.0 or foo[0] is also the same thing, if bar is foo's first element.

Consider: vorwahl = { NL: "+31", BE: "+32", US: "+1", ... };

Re:arrays

kungfuftr on 2005-04-06T22:49:57

var current = document.seas.staat.selectedIndex;
var select  = document.seas.staat.options;
var land    = select[current].value;

Surely this a a lot more simple that having some external way of doing things?

Re:arrays

Juerd on 2005-04-07T06:58:09

var staat = document.seas.staat;
var land = staat.options[staat.selectedIndex].value