Open letter to Oxfam…

Dear Oxfam,

I was happy when I heard that you are selling music online. However I wan’t so happy to learn that you only allow Windows IE use only.

Is that because you think Macintosh and Linux users don’t want to give to charity? Is it because you are unaware of the other, more secure browsers available? Or maybe you’ve signed a deal with Microsoft to use their audio file format rather than one of the many other formats available.

Also, your main music page is also built using broken and invalid code. I’ve done a new version, built using web standards which works in all browsers.

The advantages of web standards are clear to see; for example consider that the HTML code of my version of your page weighs in at a fraction the size of your HTML code. That may save you a considerable amount in bandwidth charges when applied across your whole site.

Whatever the reason for the decision to not build your websites using international standards, I’m disappointed and it’s made me have difficulties in using your site. Surely it’s in your interest to make your website as open as possible, so as many people as possible can use it and help to fund your excellent work. I firmly believe that web standards are the way forward to ensure a more open, accessible and scalable future for the web.

Yours sincerely

Chris Taylor

DOMBuilder…

A few months ago I asked the question whether it was possible for some Javascript to parse through a piece of HTML and render it all out using the “proper” DOM methods rather than the sledgehammer-to-crack-a-nut manner of innerHTML. The great Stuart Langridge commented that this woul open up a huge can of worms in case people put non-standard code into it. I agree.

Well, it seems there’s a way to do this from the other side, if you know what I mean. The clever chaps (and chapess) at Vivabit came up with this clever DOMBuilder script that allows you to build snippets of HTML code using the DOM in an almost-easy manner. Well, it’s certainly easier that createElement-ing and appendChild-ing everything.

And it’s also another neat use of the Javascript Object Notation thingamajig. Clever.

Prototype testing, Javascript with recordsets, and JSON…

Today I had the chance to mess around a bit more with the marvellous Prototype Javascript framework which in my opinion just keeps getting better and better. It makes me wish I had started using it 18 months ago when I first started getting (back) into Javascript and this thing called AJAX, it would have saved me a lot of head – and heart – ache. I’d highly recommend it.

However there’s one problem. And that’s tied to the fact that the vast majority of work I do is with databases, and therefore that means recordsets. A recordset, in case you didn’t know, is just a collection of records from a database. Say, a list of the details of all the users with a security level of ‘Administrator’. So, of course, I’m looping those records in PHP or ASP and outputting the result. So far so good. But what if I want to attach Javascript functions to each record, for example toggling a ‘more details’ section?

What I’d traditionally have to do is find out the records I’m going to be printing out, set up some kind of listener for each one at the top of the page, then print the recordset further down. That means two loops. Let me explain, in psuedo-code:

// Get all the users with a type of 'Administrator'
   $recordset = $database->getRecordset("All users who are Administrators");
// Loop all the records
   for each $user in $recordset {
// print each users name
      print $user["name"];
// print a hidden area with further details on this user
      print "";
// print a few more details about the user
      print $user["email"]
      print $user["phone"]
// end the hidden area
   print "";

What I want to do is place a Javascript listener for each username so when it is clicked the hidden area is shown for that area. Of course, using Prototype and all the other Javascript frameworks I’ve seen, you have to add a separate listener for each thing you want to listen for. That makes sense.

However the difficulty is that I need to know about all the usernames at the top of the pge, where I can create my Javascript and put it in the head section, but often I don’t open the database until further down. Yes, I know, I know, doing it all as objects sorts this problem out, but that’s not always practical for older projects.

What I need is a method in Prototype that will allow me to listen for elements with attributes like what I want. In my example (using real code this time) I could create the following using my server-side code:

User 1
   

user1@email.com, 11111&lt/p>

User 2
   

user2@email.com, 22222&lt/p>

User 3
   

user3@email.com, 33333&lt/p>

Then I would set my Javascript code to look for all elements with and ID like ‘user-[whatever]’ and set a listener for each element it finds. Like this:

// Loop all elements with ID like 'user-' then any series of numbers, using regular expression syntax
for (var i=0; i    // get the value from the ([0-9]*) section for this element
   var thisId = document.getElementsByIdLike('user-([0-9]*)')[i][0];
   // for each element found set a listener using Prototype
   Event.observe(document.getElementsByIdLike('user-([0-9]*)')[i].id, 'click', toggleDetails, false);
}

It’s a bit rough-and-ready (what else do you expect from me?) but I think this function would be really useful. Does anyone else agree? Does anyone else get what I’m on about?

The other thing I’ve been using today is JSON, a really lightweight way of transferring data about. It’s as easy as pie to parse it using Javascript, and makes a big step forward from my usual blunderbuss method of returning chunks of HTML from AJAX calls. Maybe this goes to prove I’m moving on in my geekdom. I’ll leave it up to you to decide whether that’s a good thing.

Web standards in action…

I had a nice email from a client late on Friday night saying that their website was on the first page of Google for one of their most important products. The site: House of Crystal. The search: glass trophies (note: this position may change in the future, so get ’em while they’re hot!).

The great thing about this is we’ve not done anything special with the site – it’s just plain HTML pages. However I built the site using web standards, which means the text on the pages has semantic value. That means Google (and other text-dependant ystems such as screenreaders) can tell easily which bits of text have different types of meanings. Meaning like “this is a heading”, “this is a paragraph”, “this bit should be emphasised” and much more.

It may be a minor point to some, and the number of web developers using web standards may be small at the moment, but I firmly believe this is the future of the web. And, in case you don’t think using web standards has much tangible benefit, look no further than House of Crystal – they’re on the first page of Google, and all with very little traditional SEO effort.

The customer is always right…

Yes, sure. As the good people on Andy Budds website have made clear, some clients are just clueless. That goes for managers, too. If you want to feel my pain, just read that list.

My three things:

1) There is no substitute for good content (and no, I won’t ‘just make something up’)
2) There is no substitute for good design (and no, I won’t ‘just use the Powerpoint template’)
3) There is no substitute for hard work (and no, it won’t happen overnight)