[thelist] re: checkboxes, DOM, rows, etc

Tom Dell'Aringa pixelmech at yahoo.com
Thu Sep 19 16:39:01 CDT 2002


> --- ".jeff" <jeff at members.evolt.org> wrote:
> > tom,
> >
> > ><><><><><><><><><><><><><><><><><><><><><><><><><><><><><
> > > From: Tom Dell'Aringa
> > >
> > > function checkAllBoxes(targetform)
> > > {
> > >   for (i = 0; i < targetform.elements.length; i++)
> > >   {
> > >     if (targetform.elements[i].type == "checkbox")
> > >     {
> > >       if(targetform.elements[i].checked == false)
> > >       {
> > >         targetform.elements[i].checked = true
> > >       }
> > >     }
> > >   }
> > > }
> > ><><><><><><><><><><><><><><><><><><><><><><><><><><><><><
> >
> > this will work if all the checkboxes have unique names.
> >
> > ><><><><><><><><><><><><><><><><><><><><><><><><><><><><><
> > > cell.innerHTML = "<input type=\"checkbox\" id=\"box1\"
> > > class=\"checkbox\" />";
> > ><><><><><><><><><><><><><><><><><><><><><><><><><><><><><

Ok, I changed the function that writes the new rows so it adds both
and id and a name attribute (they are the same per row, but each id
and name is unique for each row).

Here is the full function I use to add a row:
----------
function addDoctor(name, city, id)  //i use id to set id and name
{
var docTarget = window.frames['docs'].document;
var docBody = docTarget.getElementsByTagName("body").item(0);
var myTable = docTarget.getElementById('mydocs');
var myTableBody = docTarget.createElement("TBODY");

//create row
row = docTarget.createElement("TR")

//create cells

cell = docTarget.createElement("TD")
cell.setAttribute("width", "16");
cell.innerHTML = '<img src="view.gif" width="14" height="14" alt=""
/>';
row.appendChild(cell)


cell = docTarget.createElement("TD")
cell.setAttribute("width", "16");
cell.innerHTML = '<input type="checkbox" id="'+id+'" name="'+id+'"
class="checkbox" />';
row.appendChild(cell)


//-----
cell = docTarget.createElement("TD")

textVal = name;
textNode = docTarget.createTextNode(textVal)
cell.innerHTML = '<label for="box1">' + name + '</label>';
//cell.appendChild(textNode)
row.appendChild(cell)

cell = docTarget.createElement("TD")

textVal = city;
textNode = docTarget.createTextNode(textVal)
cell.appendChild(textNode)
row.appendChild(cell)

myTableBody.appendChild(row)
myTable.appendChild(myTableBody)
docBody.appendChild(myTable)
}
---------------------

The function quoted above is the one to check the boxes.

Now, when i use an alert to find the length of
targetform.elements.length when the page loads, I get a THREE (3) --
which is odd, since only the control checkbox (the one you click to
select all) and the default row are there...thats TWO.

Now, if I add a row - or rows no matter how many, the alert always
says TWO after that...and of course the script is not checking the
boxes at all.

Is there something I have to do to make sure these new checkboxes in
the new rows get added to the form..I am severely stumped. Its all
the more aggravating because this is merely a dog and pony show.
Dynamically it would be easy, I'd have a real table there...

Tom


=====
var me = tom.pixelmech.webDeveloper();

http://www.pixelmech.com/
http://www.maccaws.com/
[Making A Commercial Case for Adopting Web Standards]

__________________________________________________
Do you Yahoo!?
New DSL Internet Access from SBC & Yahoo!
http://sbc.yahoo.com



More information about the thelist mailing list