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

04-13-2012, 02: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!!

<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>

04-13-2012, 04: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.

04-13-2012, 07: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"';?>


Thanks so much!