work

Javascript form iteration - compatibility hell

06.14.08 | Permalink | Comment?

I had to write a “simple” javascript iterating through all the existing form elements, check if its a text input, and enable/disable it based on action. Googled “javascript iterate form element“, pulled out this piece of code and it works fabulously on Firefox. Great, simple 5 min job.

var e = document.getElementById("my-form").elements;
for(i in e) {
  if((e[i].type == ‘text’) && (e[i].name.indexOf(’stock’) > 0))
    …do something…
}

Next day, checked again in Internet Explorer and the script failed to execute with “type is null or not an object” error. Thereafter, went into full 6 hours of googling until I stumbled upon the differences of form iteration between IE and Firefox. To have it working in both, you probably want to iterate using elements length

for (var i=0; i < e.length; i++) {
  if((e[i].type == ‘text’) && (e[i].name.indexOf(’stock’) > 0))
    … do something…
}

Still can’t believe I spent 6 precious weekend hours on this problem.

creative

Happy Father’s Day

06.12.08 | Permalink | Comment?

Great advertisement from Durex. Simple, effective and almost comical :)

blips, pda

Hello World

06.11.08 | Permalink | Comment?

Hello World from PDA on the 30 min train ride to work. Twitter, iphone, sexier pda, 7.2mbps GPRS speed, are game changing (at least in this part of my world) and redefines the meaning of mobility. Japan has been there 5 years back and we are slowly catching up. Did you know 5 out of 10 best selling books in Japan 2007 were written on mobile phones? I am giving blogging another go. いらしゃい!


» Next Entries