in reply to OT? Checkbox list with CGI/Javascript

Here is one method that I have used when I wanted to know which checkboxes were present on a page. (Way back when I did web work.)

For each "thing" you want in the list produce two fields in the form, one a checkbox and one a "hidden" field. Call the checkbox fields something like "cb_N" and the hidden fields something like "hd_N" where N is a number from 1 to N and you have N "things".

When the data is submited you will get a list of all "hd_*" fileds but the checkboxes are only submitted if they are checked off. So you loop over all of the "hd_N" values and see if the "cb_N" was submitted or not for that number "N".
  • Comment on Re: OT? Checkbox list with CGI/Javascript

Replies are listed 'Best First'.
Re^2: OT? Checkbox list with CGI/Javascript
by rashley (Scribe) on Nov 14, 2005 at 13:13 UTC
    Again, the problem I see with this solution is that I won't know how many "N"s I'll have, since the list is being created dynamically depending on the data.
      You will know how many 'N's there are because there is one "hidden" variable for each 'N'. That's what the hidden variables are for. If a hidden variable was submitted then you know a checkbox exists.