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 http://stein.cshl.org/WWW/software/CGI/

Here's a quick sample:

popup_menu(-name=>'color',
          -values=>['red','green','blue','chartreuse'])

Matthew Lock
Thursday, February 05, 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.

http://norman.walsh.name/2003/06/01/xmlnotoo

Lou
Thursday, February 05, 2004

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

radioClick=function(){
    alert("selected " + this.title);
}

windowOnLoad=function(){
    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.

Wayne
Thursday, February 05, 2004

*  Recent Topics

*  Fog Creek Home