[Javascript] select all checkboxes script

David Dorward david at dorward.me.uk
Tue Feb 7 08:48:33 CST 2006


On Tue, Feb 07, 2006 at 03:41:04PM +0100, Michael Borchers wrote:
> >// and on the checkbox fields (all of the same id/name)

> the script works fine, but not if the name/id is
> 
> chkbxFldName[0], chkbxFldName[1], chkbxFldName[2] etc...!? :( 

It does say that the name / id must be the same. 

Having the id the same is forbidden (as is having [ or ] in an id),
but having the name the same is the standard way of creating a control
group in HTML.

PHP just has some unusual (i.e. unlike every other standard form
processing library) naming conventions.

You could loop through them with something along the lines of:

var count = 0;
while (var field = 
  document.forms['formname'].elements['chkbxFldName[' + count + ']']) {
  doSomething(field);
  count++;
}

-- 
David Dorward                                      http://dorward.me.uk




More information about the Javascript mailing list