Fog Creek Software
Discussion Board

Objected Oriented HTML (Kind of...)

This was posted in an earlier thread:

> Does anyone foresee HTML becoming more object-oriented
> (so you could define an event handler once for all of the
> radio buttons in a group as opposed to setting it up for each
>  one), or am I on crack?

perl's cgi module provides a kind of object oriented method of generating HTML

Here's a quick sample:


Matthew Lock
Thursday, February 5, 2004

Norman Walsh posted a while back about XML not being OO (and really, if anyone knows if it is or isn't it's probably him).  It's worth a read before one starts getting all fidgety and upset about HTML not fitting into an OO model.

Thursday, February 5, 2004

You can assign a single event handler to a group of radio buttons quite easily:

    alert("selected " + this.title);

    var oEls = document.getElementsByTagName("input");
    for(var i=0;i<oEls.length;i++){
        if(oEls[i].type == "radio") oEls[i].onclick=radioClick;

window.attachEvent("onload", windowOnLoad);

// The if(oEls[i].type == "radio") condition could be eliminated from the loop if you could select only the inputs with a type of radio, which you can but I forget how.

Thursday, February 5, 2004

*  Recent Topics

*  Fog Creek Home