Question : Counting number of checked checkboxes in a form (when checkboxes are all named differently)

I have a form the consists of about 50+ checkboxes in it -- each of which are named differently

(ie: checkbox_99, checbox_127, checkbox_33, .. etc)

The checkbox names will always be different (the # values in the field names correlate to record IDs that are returned from a database query.

I'd like to update the form with a DIV that displays the number of checkboxes in the form that have been checked -- and that dynamically updates itself as boxes are checked/unchecked.

The # value in the DIV should start with "0".
As boxes are checked, the value should increment by +1.
As boxes are unchecked, .. the value should decrement by -1.

How can I accomplish this using javascript?

Thanks in advance,
- Yvan

Answer : Counting number of checked checkboxes in a form (when checkboxes are all named differently)

Hi learningunix,

the line checks if the left-most byte of 'num' is '1'.

'&num' is a pointer to the memory address where the first byte of 'num' resides. The '(char*)' casts this pointer '&num' (which is a pointer to int) to a pointer to char. Since char is a one byte data type accessing that 'pointer to char' with '*' accesses the first byte of the int. In little endian this byte has to be '1' for and 'int' which is '1' - in big endian the first byte would be '0' since the least significant byte is the most right one ...

Hope that helps,

ZOPPO

Random Solutions  
 
programming4us programming4us