Forum Moderators: coopster

Message Too Old, No Replies

Checkboxes....

         

orion_rus

11:21 am on Dec 28, 2004 (gmt 0)

10+ Year Member



Hello world i have about 15 checkboxes with name="chkbox[]" and different values. If i check any number of it. $chkbox would be consist of values devided with ",". This $chkbox i push to a database.
But when i get this value from it i have a trouble to fill this checkboxes checked. I don't know how. Can anybody help me?

Salsa

5:05 pm on Dec 28, 2004 (gmt 0)

10+ Year Member



See if this thread from a couple of weeks ago, returning checked boxes from an array [webmasterworld.com], will help you.

jatar_k

5:06 pm on Dec 28, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



if the set you get back is a list of values seperated by a comma then you will need to split or explode them and then you can check each one.

$wichcheckboxes = 'check1,check4,check7,check15';
$chkarr = split(',',$wichcheckboxes);

then when you check each checkbox you could do something like

<input type="checkbox" name="chkbox[]" value="check1" <? if(in_array('check1',$chkarr)) echo ' checked';?>>

should work. If the checkbox values were numbered you could also just use a loop to build them all and check all in a couple lines of code.

orion_rus

9:28 pm on Dec 28, 2004 (gmt 0)

10+ Year Member



great it works.
Thanks all for help me)