Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Dec 2006
    Posts
    2
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Checkbox: How to have it checked by default?

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

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

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    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 Code:
    <?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.

  • Users who have thanked Fou-Lu for this post:

    chiappa (04-13-2012)

  • #3
    New to the CF scene
    Join Date
    Dec 2006
    Posts
    2
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Code:
    <?php echo $group->approvals != COMMUNITY_PRIVATE_GROUP ? '' : ' checked="checked"';?>
    Did not work.

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

    Thanks so much!


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •