1

I use FullCalendar.io script and I want to query into modal when clicking on dayEvent from DB MySQL filter by month value from the calendar. I have standard code FullCalendar and into the same page have Modal with DIV id="lunaTime". Need this value from DIV to $var to call a Query MySQL. Any solutions?

$('#calendar').fullCalendar({
header: {
    left: 'prev,next today',
    center: '',
    right: 'title'
},
dayClick: function(start, end, jsEvent) {
    lunatime = $.fullCalendar.moment(start).format('MMM');
    endtime = $.fullCalendar.moment(end).format('HH:mm');
    starttime = $.fullCalendar.moment(start).format('dddd, DD MMMM YYYY, HH:mm');
    var mywhen = starttime + ' - ' + endtime;
    var myluna = lunatime;
    start = moment(start).format();
    end = moment(end).format();
    $('#ModalAdd #lunaTime').text(myluna);
    $('#ModalAdd #startTime').val(start);
    $('#ModalAdd #endTime').val(end);
    $('#ModalAdd #when').text(mywhen);
    $('#ModalAdd').modal('show');
}});

Into php page have <div id="lunaTime"></div>

enter link description here

I try AJAX:

    <script>
    function showUser(str) {
        if (str == "") {
            document.getElementById("title").innerHTML = "";
            return;
        } else {
            if (window.XMLHttpRequest) {
                // code for IE7+, Firefox, Chrome, Opera, Safari
                xmlhttp = new XMLHttpRequest();
            } else {
                // code for IE6, IE5
                xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
            }
            xmlhttp.onreadystatechange = function() {
                if (this.readyState == 4 && this.status == 200) {
                    document.getElementById("title").innerHTML = this.responseText;
                }
            };
            xmlhttp.open("GET","ajax.php?q="+str,true);
            xmlhttp.send();
        }
    }
</script>
                    <div id="lunaTime"></div>
                    <div id="title"></div>

And for extract value from DIV i try this:

$(document).ready(function(){
  $("#ModalAdd").on('shown.bs.modal', function(){
    document.getElementById("lunaTime").onload = showUser(this.value);
    alert(this.value);
  });
});

Into AJAX $q value is 0, script value is 0. Where is the mistake ?

ULY
  • 23
  • 5
  • you can't. you can pass into hidden HTML field. and when it submits you can post it via the form. if you need security over that variable then use AJAX. – Sayed Mohd Ali Jul 12 '19 at 09:28
  • https://jsfiddle.net/iulianmihu/gjv7sLrn/20/ – ULY Jul 12 '19 at 09:43
  • how call ajax into javascript ? Need change the value when click on another dayEvent... – ULY Jul 12 '19 at 09:51
  • https://stackoverflow.com/questions/1917576/how-to-pass-javascript-variables-to-php/57004349#57004349 – Sayed Mohd Ali Jul 12 '19 at 09:56
  • not helping me this ... – ULY Jul 12 '19 at 10:06
  • 1
    please create a new question and explain how your question is different because it is marked as duplicate by the moderators. you have to make a new question with a different name. – Sayed Mohd Ali Jul 12 '19 at 10:22
  • not helping you how? What don't you understand, specifically? Once your user clicks to close the modal and save the event, you need to make an AJAX request to your server to send all the necessary data, including the content of the div. You can use JavaScript to read the text value from the div and attach it to the data of the request. PHP can then receive this request and use the received data within the SQL query. Is there a particular aspect of this process which you still don't understand? Have you researched into AJAX requests and tried to write one yet? – ADyson Jul 12 '19 at 11:19
  • sry ... i try ajax but from my DIV extract only value 0 not mounth. – ULY Jul 13 '19 at 10:38

0 Answers0