Wrox Home  
Search P2P Archive for: Go

  Return to Index  

javascript thread: Checkboxes and Netscape


Message #1 by "Brian Mains" <bgmst5@y...> on Fri, 15 Jun 2001 18:47:38
Hi Brian,

Try using the code listed below (tested and working in Netscape 3+ and IE 4+).

Just make sure that you name your form correctly:-

<FORM name="staffwanted">

and that you name your 'master' checkbox accordingly:-

<input type="checkbox" name="allbox" onClick="CheckAll();">

Here's the function:-

function CheckAll()
{
         for (var i=0;i<document.staffwanted.elements.length;i++)
         {
                 var e = document.staffwanted.elements[i];
                 if ((e.name != 'allbox') && (e.type=='checkbox'))
                 e.checked = document.staffwanted.allbox.checked;
         }
}

The only assumption made is that these are the only checkboxes in the form 
- if you only want to check only a select group of checkboxes, you will 
have to modify the above code to loop over only a certain number, rather 
than all the form elements.

Cheers,

Ben

At 18:47 15/06/01 +0000, you wrote:
>Hello,
>
>I want to have 8 checkboxes that are the properties to search for.  The
>first checkbox is a checkbox that is for all of the checkboxs.  Whenever
>the user clicks that one, all of the checkboxes are clicked.  The input
>tag looks like:
>
><input type="checkbox" name="txtProperties" value="ALL"
>        onclick="checkBoxes(this.form)">All
>
>The other 7 are in the same syntax (without the onclick event though).
>
>The javascript function looks like:
>
>function checkBoxes(frm) {
>   if ( document.frm.txtProperties(0).checked == true ) {
>     for ( var i = 1; i < document.frm.txtProperties.length; i++ ) {
>       document.frm.txtProperties(i).checked = true;
>     }
>   }
>   else {
>     for ( var i = 1; i < document.frm.txtProperties.length; i++ ) {
>       document.frm.txtProperties(i).checked = false;
>     }
>   }
>}
>
>It works fine in IE, but doesn't work at all in Netscape.  It says
>document.frm has no properties.  I keep getting this for everything else
>too for some reason.
>
>Thanks,
>
>Brian Mains


http://benmeg.com

  Return to Index