mercredi 23 août 2017

How to display the checkbox value on same page without submit button and form in php?

I have a checkbox and If any user selects the check box then the value of checkbox will display on the same page without refresh the page.

index.php

<input  type="checkbox" value="<?php echo $value;?>" name="value_r" id="value_r"/>

if(!isset($_POST['value_r']))
echo $_POST['value_r'];
}

If ajax is good then can any one know how to display the value with ajax?

$("#value_r").change(function () {
    var isChecked = $(this).is(":checked") ? 1:0;
        $.ajax({
        type: "POST",
        url: "index.php",
        async: true,
        data: { isChecked: isChecked },
        success: function (response) {
        }
    });
  });




Aucun commentaire:

Enregistrer un commentaire