1

I'm trying to create a simple calendar utilizing my knowledge in PHP and MySQL, but I want to have it as instant as possible. I'm using an article and the plugin sourcerer. At first I created a simple input for Year-Month like so:

<form>
  <lable>Date:</lable>
  <input type="month" id="dateCal" name="dateCal" value="{source}<?=date('Y-m')?>{/source}" onchange="func(this.value)">
</form>

My idea is to get that input and use it for all my following calculations in PHP, however, I need to get it first, I'm using the following code:

<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script>
function func(selectedValue) {
    $.ajax({
        url: 'index.php',
        type: 'POST',
        data: {valueYM: selectedValue},
        success: function() {
            console.log("Data sent!");
        }
    });
}
</script>
{source}
<?php
if ($_REQUEST['valueYM']) {
    $val = $_REQUEST['valueYM'];
    echo $val;
}
?>
{/source}

As far as I know, that should work, that should return the value that is in the input, however, it doesn't work, I get the console message but the PHP function is never called, the URL value is definitely wrong, I don't really know how to tweak it and I barely found any info in google, could you give me a hand?

1
  • Welcome to JSE, please take our tour. Dec 1, 2020 at 20:42

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Browse other questions tagged or ask your own question.