Forum Moderators: coopster

Message Too Old, No Replies

Checkbox woes!

         

Dhruv

9:13 pm on Oct 19, 2004 (gmt 0)

10+ Year Member



I've searched high and low of this and i've worked on this over 7 days i still cant work it without bugs.

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

jollymcfats

9:36 pm on Oct 19, 2004 (gmt 0)

10+ Year Member



There's no way to directly detect unchecked checkboxes. The browser simply doesn't send anything if the box is not checked.

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.

Dhruv

9:38 pm on Oct 19, 2004 (gmt 0)

10+ Year Member



yes, thats what i was doing, until i came to the problem where i wanted to add new IDs that weren't existant on the DB.

Its getting more and more complicated. lol

jollymcfats

9:55 pm on Oct 19, 2004 (gmt 0)

10+ Year Member



Well, finding unknown checked boxes is easy- take all of the keys from input that start with emo_, strip off that prefix and you know what is checked regardless of whether you were expecting it or not.

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.

StupidScript

11:40 pm on Oct 19, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



What does your db table look like?

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?

grandpa

6:58 am on Oct 21, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Dhruv

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.