Welcome Guest, Not a member yet? Register   Sign In
Checkbox and Jquery
#1

[eluser]bondjp[/eluser]
Hi I'm having a problem getting the value of the checkbox into my controller.
The problem is the alert windows is always telling me the value is unchecked(0).
Can someone please tell me what i'm doing wrong?

View:
Code:
[removed]
function getSubs(){
var root = "<?=base_url() ?>";
if ($("#subscribe").is("checked")) {  
    // checkbox is checked
    var checked=1;
    alert(checked);
    $().load(root+"user/subscribe", {subscribe: checked} );
    } else {
        // checkbox is not checked
        var unchecked=0;
        alert(unchecked);
        $().load(root+"user/subscribe", {subscribe: unchecked} );
        
      }
       return false;
}
[removed]

....................................

<?php
    print_r($subscribe);
    if ($subscribe=='y'){
        $subscribe=TRUE;
        } else {
            $subscribe=FALSE;
    }?>
    <?php echo form_open('user/subscribe'); ?>        
    <?php $js = 'id="subscribe"';?>
    [removed]
           $(document).ready(function() {
           $("#subscribe").bind("change", getSubs);
           });
    [removed]    
<table>
    <tr>
        <td >&lt;?php echo form_label('Subscribe : '); ?&gt;</td>
        <td id="subscribe">&lt;?php echo form_checkbox('subscribe',$subscribe,$js); ?&gt;</td>
    </tr>
</table>
&lt;?php echo  form_close(); ?&gt;


Messages In This Thread
Checkbox and Jquery - by El Forum - 08-06-2010, 12:34 PM
Checkbox and Jquery - by El Forum - 08-06-2010, 12:41 PM
Checkbox and Jquery - by El Forum - 08-06-2010, 03:11 PM



Theme © iAndrew 2016 - Forum software by © MyBB