RE: [PHP-DB] HTML Forms question...
| From: | Hutchins, Richard | Date: | Tue, 19 Nov 2002 18:45:03 +0000 |
| Subject: | RE: [PHP-DB] HTML Forms question... | ||
| Groups: | php.db | ||
| Request: | Send a blank email to php-db+get-23490@lists.php.net to get a copy of this message | ||
Not only does Mike's description below work really well for a single page,
if you write all of your JS stuff like this, you can very easily use the
same script on multiple pages. Portability! Works great for me.
> -----Original Message-----
> From: Ford, Mike [LSS] [mailto:M.Ford@lmu.ac.uk]
> Sent: Tuesday, November 19, 2002 1:35 PM
> To: 'Rich Gray'; NIPP, SCOTT V (SBCSI); php-db@lists.php.net
> Subject: RE: [PHP-DB] HTML Forms question...
>
>
> > -----Original Message-----
> > From: Rich Gray [mailto:rich@f1central.net]
> > Sent: 20 November 2002 01:13
> >
> > If you name the checkbox as name="system[]" then PHP will
> > automatically
> > create an array of the checkbox values which can be
> > subsequently accessed
> > via $_POST['system'][n] - be warned however that the '[]' can
> > screw up any
> > JavaScript code that refers to the checkbox object...
>
> G'rrrr -- not this old chestnut again!
>
> It only "screws up" your JavaScript if you don't write your
> JavaScript to
> allow for it.
>
> It's really very simple: *by* *definition* in JavaScript, the notation
>
> a.b
>
> is *identical* to
>
> a["b"]
>
> Thus, if you have a single checkbox named with name="system",
> then you can
> access it in either of these ways:
>
> document.form.system
> document.form["system"]
>
> By extension, if you have multiple checkboxes all named with
> name="system[]", you can refer to them as:
>
> document.form["system[]"][0]
> document.form["system[]"][1]
> document.form["system[]"][2]
>
> etc...
>
> I know this works because I've been using it for years (even before I
> started programming with PHP!).
>
> Cheers!
>
> Mike
>
> ---------------------------------------------------------------------
> Mike Ford, Electronic Information Services Adviser,
> Learning Support Services, Learning & Information Services,
> JG125, James Graham Building, Leeds Metropolitan University,
> Beckett Park, LEEDS, LS6 3QS, United Kingdom
> Email: m.ford@lmu.ac.uk
> Tel: +44 113 283 2600 extn 4730 Fax: +44 113 283 3211
>
> --
> PHP Database Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>