First off thanks for the reply.

When I click the "test" button I get "Error: 'length' is null or not an
object."

I used

<script language=javascript>

  function func( field ) {
    for ( i = 0; i < field.length; i++ )
      field[i].checked = true ;
  }

</script>

<input type="checkbox" name="email[]" value="5">
<input type="checkbox" name="email[]" value="2">
<input type="checkbox" name="email[]" value="1">

<input type=button value=test onclick="func( document.forms[ 0
].elements[ 'email[]' ] )">



----- Original Message -----
From: "Krzysztof Kocjan" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Wednesday, October 03, 2001 2:47 AM
Subject: Re: [PHP] php & javascript


> Try document.myform.elements['email[]'] like below
>
> <script language=javascript>
>
>   function func( field ) {
>     for ( i = 0; i < field.length; i++ )
>       field[i].checked = true ;
>   }
>
> </script>
>
> <form name=myform>
> <input type=checkbox name="email[]" value="email_1">
> <input type=checkbox name="email[]" value="email_2">
> <input type=checkbox name="email[]" value="email_3">
> <input type=checkbox name="email[]" value="email_4">
> <input type=checkbox name="email[]" value="email_5">
> <br>
> <input type=button value=test onclick="func( document.forms[ 0
> ].elements[ 'email[]' ] )">
> </form>
>
>
>
> Krzysztof
>
> [EMAIL PROTECTED] wrote:
> >
> > Hey all!
> >
> > I'm including some javascript that enables a button in a form
<input type="button" name="CheckAll" value="Check All"
> > onClick="checkAll(document.myform.email)">                to check all
the check boxes at once. (I have an array of check boxes from a mysql db)
> >
> > I use:
> >
> > <SCRIPT LANGUAGE="JavaScript">
> > <!-- Begin
> > function checkAll(field)
> > {
> > for (i = 0; i < field.length; i++)
> >  field[i].checked = true ;
> > }
> >
> > function uncheckAll(field)
> > {
> > for (i = 0; i < field.length; i++)
> >  field[i].checked = false ;
> > }
> > //  End -->
> > </script>
> >
> > So... In order to use this script my button has to have
onClick="checkAll(document.myform.email)" and my check boxes have to have
name="email" but i need to name them name="email[]" in order to pass the
variables as an array in php. ive tried using
onClick="checkAll(document.myform.email[])" but that just gives me an error
for obvious reasons im sure. I don't know jack about javascript, so if you
know of a better way to make a button that selects all check boxes or
another way to code how the check boxes values are passed to the next page,
I would be so greatful.
> >
> > Thanks!
> > Nate
>
> ------------------------------------------------------------
> 99% trafien. 1% rezerwy, zeby innym nie bylo przykro.
> Nowe Centrum Wyszukiwania >> http://szukaj.interia.pl/
>


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to