0

Hai I want to set javascript variable (getdate1) as PHP variable to compare the dates with database value to display event details. I attached the attachement of how alert box will work.

        var getdate1 = document.getElementById("eventDayName").innerHTML = selectedDate.toLocaleString("en-US", {
            month: "long",
            day: "numeric",
            year: "numeric"
        }); 

        alert(getdate1); 

enter image description here

1

1 Answer 1

0

HTML: <input type='hidden' id='myDate' name='myDate'> JS: document.getElementById('myDate').value = getDate1; PHP: $date = $_POST['myDate'];

Explanation: Make a hidden html element. Set its value with javascript. Get its value with PHP.

Sign up to request clarification or add additional context in comments.

3 Comments

If you go to the console and view the value of the HTML element (document.getElementById('myDate').value), is it displaying?
Uncaught ReferenceError: getDate1 is not defined at HTMLDivElement.gridTable.onclick (calender.php:745) gridTable.onclick @ calender.php:745
Try assigning the date to getDate1 and the dom element separately, like this: var getDate1 = selectedDate.toLocaleString("en-US", { month: "long", day: "numeric", year: "numeric" }); document.getElementById("eventDayName").innerHTML = getDate1;

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.