Thursday, November 14, 2013

need help with check/uncheck all checkbox [cakephp]

I need help with this. I'm creating a checkbox to select or deselect the country options. Please help to give some clues and explaination. I'll be very grateful. Thanks in advance. 
Below are the code:

Location: View/country/add.ctp file

<script type="text/javascript">
$(document).ready(function () {
    $('#selectall').click(function () {
         var checked = $(this).is(':checked');
        
        $('.selectedId').each(function () {
            var checkBox = $(this);
            console.debug(checkBox);
            if (checked) {
                checkBox.prop('checked', true);                
            }
            else {
                checkBox.prop('checked', false);                
            }
        });
        
    });
});
</script>
    <div>
<?php echo $this->Form->create('Showcase'); ?>
    <fieldset>
        <legend><?php echo __('Add Showcase Product'); ?></legend>
    <?php
        echo $this->Form->input('p_start', array('label' => 'Start Date'));
        echo $this->Form->input('p_end', array('label' => 'End Date'));
        echo $this->Form->input('priority', array('label' => 'Priority'));
        echo $this->Form->input('Select all Country', array("type" => "checkbox", 'id'=>'selectall'));
        echo $this->Form->input("Country", array("options" => $viewData["countryList"], "multiple" => "checkbox", "onclick" => "resetSelectAll();" , "class" => "selectedId" , "name" => "selectedId")); 
?>
    </fieldset>
    
  
<?php
echo $this->Form->end(__('Submit'));
echo $this->Html->link('Back', array('action' => 'listShowcases'));
?>
</div>

--
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP
 
---
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cake-php+unsubscribe@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/groups/opt_out.

No comments: