Forum Moderators: coopster
To be short i need a way to detect:
Unchecked checkboxes
Checked checkboxes
irrespective of their name without using a hidden feild to send out total number of checkboxes.
The problem is basically this, i'm creating list of smileys read from a DB. BUT say you have 28 smileys so IDs go from 0-27. Now when a smiley is removed, and another is added there still are only 28 smileys but the IDs are now 0-26 and 28 (with 27 missing). This gap can get larger or there could be any number of them. so a total is useless as the loop wuold go up to 27 (which is the total) but it wouldn't cover the 27th smiley with ID 28!
I cant name the checkboxes as an array because if i do i cant map it onto the DB (when the user wants to change tghe code) so the name HAS to be emo_$id (where $id is taken off the DB)
i need a simple way of saying how many checkboxes there are, how many checked and how many not checked.
Could someone please help me out? I'd be very greatful
Without using a hidden field, I think your best bet is to read in your active IDs from the database, then check the request data for each of them in succession.
So you'd check for emo_ plus 0-26 and 28, and keep track of which ones you found in _REQUEST and which ones you didn't.
But finding totally unknown unchecked boxes- you're pretty much sol. You need a hidden field or some other mechanism to tell you what possible values may be there.
It sounds like you may be creating and naming the icons before placing them in your db?
Maybe FIRST dump the icon into your db. That will create a record with (apparently) an auto_increment id. THEN, pull the icon array from the db and build your form from that on each request. When a user checks an icon box and submits, that icon is used because its reference was created directly from whatever was in the db, regardless of gaps in the auto_increment id sequence.
<input type="checkbox" name="<?=$icon_id?>"> <?=$icon_blob_field?>
Something like that?
Would it be feasible to check the state of the boxes with Javascript? I know you can get a JS counter [webmasterworld.com] to return a value for you.