How to insert custom fields value in footer javascripot script
-
So I’m trying to do add a text value of custom fields, so that it is used as the deadline date for a countdown. Do note I’m no JS expert, just the basics.
Here’s the code:<script> // Set the date we're counting down to var fecha_contador = acf.get('fecha_del_contador'); var countDownDate = new Date(fecha_contador).getTime(); // Update the count down every 1 second var x = setInterval(function() { // Get today's date and time var now = new Date().getTime(); // Find the distance between now and the count down date var distance = countDownDate - now; // Time calculations for days, hours, minutes and seconds var days = Math.floor(distance / (1000 * 60 * 60 * 24)); var hours = Math.floor((distance % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60)); var minutes = Math.floor((distance % (1000 * 60 * 60)) / (1000 * 60)); var seconds = Math.floor((distance % (1000 * 60)) / 1000); // Display the result in the element with id="demo" /*document.getElementById("demo").innerHTML = days + "Días " + hours + "Horas " + minutes + "Min " + seconds + "s";*/ document.getElementById("days").innerText = days; document.getElementById("hours").innerText = hours; document.getElementById("minutes").innerText = minutes; document.getElementById("seconds").innerText = seconds; // If the count down is finished, write some text if (distance < 0) { clearInterval(x); document.getElementById("demo").innerHTML = "Expirado"; window.location.href = "https://www.w3schools.com"; } }, 1000); </script>
Viewing 3 replies - 1 through 3 (of 3 total)
Viewing 3 replies - 1 through 3 (of 3 total)
- The topic ‘How to insert custom fields value in footer javascripot script’ is closed to new replies.