Schokea
Schokea

Reputation: 708

Dynamic Checkbox wont do uncheck work

Hi I am dynamically adding checkboxes to a form with the followng code:

<table>
<tr>
    <?php foreach ($checks as $che) : ?>
        <td><?php echo $this->Form->checkbox($che, array('class' => $che, 'name' => $che)); ?></td>
    <?php endforeach; ?>
</tr>

which works fine and then in jquery im trying to do something depending on whether its checked or not with the following code:

$('.Variables:checkbox').live('click', (function()
{
    if($('.' +  this.name).prop("checked", true))
    {
        $("#accordion").find('h3').filter(':contains('+this.name+')').show();

    }
    else if($('.' +  this.name).prop("checked", false))
    {
        $("#accordion").find('h3').filter(':contains('+this.name+')').hide();
    }
}));

The first time i click the checkbox it works fine and the h3 tag appears but then when i try click it again it doesn't hide like it should.

any help would be great.

Thanks in advance.

Upvotes: 0

Views: 147

Answers (1)

Schokea
Schokea

Reputation: 708

I've solved it but thanks for your replies

$('.Variables:checkbox').on('click', (function()
{
    if($(this).prop("checked"))
    {
        $("#accordion").find('h3').filter(':contains('+this.name+')').show();  
    }
    else
    {
        $("#accordion").find('h3').filter(':contains('+this.name+')').hide();
    }
}));

Upvotes: 1

Related Questions