0

Hi I am trying to know whether the checkbox is checked so I can display a message and if not another message will got displayed. I tried several times and it didn't work. It will just alert True when I check and uncheck.

AJAX code:

    $('#check').click(function(){
        var check= $(this).val();

        $.ajax({
            url: './opt/index_opt.php',
            type: 'POST',
            data: {check:check},
            success: function(data){
                alert(data);
            }
        });
    });

This is my PHP file:

<?php
    session_start();
    include "../db.php";
    $user= $_SESSION['id'];
    if(isset($_POST)){
        $check = $_POST['check'];
        if(isset($check)){
            echo 'True';
        }else{
            echo 'False';
        }
    }
?>
Dustin Scott
  • 67
  • 10
  • Note that when you set the value in jQuery like `data: {check:check}`, it will always be set in php. Send a value instead and check for that value. – jeroen Jul 07 '14 at 23:17
  • change the line where you assign the variable to this: `var check= $(this).filter('input:checked').val();` – Burak Jul 07 '14 at 23:20
  • When I check on it, it returns false even when I uncheck it will return false I swear I tried a lot of ways – Dustin Scott Jul 07 '14 at 23:24

0 Answers0