Forum Moderators: coopster

Message Too Old, No Replies

Populating hidden checkboxes

         

scalp8

6:24 pm on Jan 7, 2009 (gmt 0)

10+ Year Member



I have a number of categories that have within them checkboxes that stay hidden until requested. I am able to get the selected checkboxes to save to the SQL database, but when they're pulled again all checkboxes are empty. Here's one of the checkbox categories:

<div onclick="javascript:shohide_y('interest_businessnetworking')" style="text-align:left; font-family:arial" ><em><strong>Business Networking</em></strong>
<a href="#" onclick="shohide_y('interest_businessnetworking')" style="font-size:75%;font-family:arial"><span id="interest_businessnetworking_sh">show</span></a>
</div>

<div id="interest_businessnetworking" style="display:none; text-align:left; font-size:85%; font-family:arial">
<table width="100%">
<?php if(!empty($arrBusinessList)) {
$arrLent=count($arrBusinessList);
$posRow=floor($arrLent/4);
?>
<?php if($arrLent<=4){?>
<tr valign="top">
<?php foreach($arrBusinessList as $value){?>
<td width="25%">
<input onClick="putValue(this)" type="checkbox" name="business" value="<?=$value?>" ><?=$value?> </td>
<?php } ?>
</tr>
<?php }else{ ?>
<?php for($i=0; $i<=$posRow; $i++){

$posCol=$posCol+4;
?>
<tr valign="top">
<?php if($i==0) {
$posCol=0;
$Col_lent=4;
?>
<?php for($j=$posCol; $j<$Col_lent; $j++){ ?>
<td width="25%">
<input onClick="putValue(this)" type="checkbox" name="business" value="<?=$arrBusinessList[$j]?>" ><?=$arrBusinessList[$j]?> </td>
<?php } ?>
<?php }else {
$posCol=$Col_lent;
$Col_lent=$Col_lent+4;
?>
<?php for($j=$posCol; $j<$Col_lent; $j++){ ?>
<?php if(!empty($arrBusinessList[$j])){?>
<td width="25%">
<input onClick="putValue(this)" type="checkbox" name="business" value="<?=$arrBusinessList[$j]?>" ><?=$arrBusinessList[$j]?> </td> <?php } ?>
<?php } //end of j loop?>
<?php } //end of else?>
</tr>
<?php } //end of the i loop?>
<?php } //end of else?>
<?php } //end of !empty?>
</table><input name="I_business_net" id="I_business_net" type="hidden">
</div>
<hr />

I realize that a lot of this is dictating the rules of how it opens once not hidden, but I included everything just in case that's where the problem was. Because the checkboxes aren't listed out one by one (for example there are 4 checkboxes within the shown category), and in the database column storing this information is not simple yes or no (in the I_business_net column there is either nothing or one or more of the selected categories so that a user may have "conferences, expos, tradeshows" to show that they have 3 items selected in that category. Another way to phrase my question may be "how do I populate the checkboxes by looking into a SQL column that contains words instead of simple Y or N and then tell which checkboxes correspond to those words since they are not all listed out?" Thank you for any help!

coopster

6:03 pm on Jan 9, 2009 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Another way to phrase my question may be "how do I populate the checkboxes by looking into a SQL column that contains words instead of simple Y or N and then tell which checkboxes correspond to those words since they are not all listed out?"

I use identifiers. Let's say your options were stored in an options table with two columns, the identifier and the description:


ID Description
-- -------------
1 businessOne
2 businessTwo
3 businessThree

I would store them in the "options selected" table as 1, 2, or 3. Then it is much easier to match them up by using the ID in the "value" attribute of the checkbox and use the description as the text next to the checkbox.