...

View Full Version : Checkbox: How to have it checked by default?



chiappa
04-13-2012, 03:45 AM
Hi! I have a checkbox that I want to have checked by default. The code below has it unchecked by default, how can I change it? Thanks!!


<td>
<span class="value label jomNameTips" title="<?php echo JText::_('COM_COMMUNITY_GROUPS_APPROVAL_TIPS');?>">
<input type="checkbox" name="approvals" id="approve-private" value="1"<?php echo ($group->approvals == COMMUNITY_PRIVATE_GROUP ) ? ' checked="checked"' : '';?> />
<label for="approve-private" class="label lblradio"><?php echo JText::_('COM_COMMUNITY_GROUPS_PRIVATE_LABEL');?></label>
</span>
</td>

Fou-Lu
04-13-2012, 05:23 AM
You mean move it from checked only if $group->approvals is COMMUNITY_PRIVATE_GROUP to checked unless $group->approvals IS NOT COMMUNITY_PRIVATE_GROUP?


<?php echo $group->approvals != COMMUNITY_PRIVATE_GROUP ? '' : ' checked="checked"';?>

Should do that. The only problem I can see is that $group->approvals isn't verified in any fashion, so you may need to expand that to use isset($group->approvals) && $group->approvals != COMMUNITY_PRIVATE_GROUP as the condition. That way if no approvals is set, or if the group approvals is not the private group, its checked.

chiappa
04-13-2012, 08:46 AM
<?php echo $group->approvals != COMMUNITY_PRIVATE_GROUP ? '' : ' checked="checked"';?>

Did not work.


<?php echo isset($group->approvals) && $group->approvals != COMMUNITY_PRIVATE_GROUP ? '' : ' checked="checked"';?>

Worked!

Thanks so much!



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum