Javascript Dynamic Field Timing

Use Javascript to show and hide text fields based on time

Marc Rosenberg avatar
Written by Marc Rosenberg
Updated over a week ago

You can use Javascript to show and hide dynamic text fields. For example, if you have a video where part of the video doesn't have pricing, you can use the code example below to hide fields based on the timing of the video. Add this code to a presentation's JS tab and modify the code to suit your requirements.

var fields = document.getElementById('fields'); var children = fields.children; calibrate(); var video = document.querySelector("video"); video.loop=false; video.addEventListener('ended', function(e){ console.log("Video Ended") video.play(); calibrate(); }, true); function showPrices(){ for(var i =0; i<= 11; i++){ children[i].classList.add("show-prices"); } } function hidePrices(){ for(var i =0; i<=6 ; i++){ children[i].classList.remove("show-prices"); } } function calibrate() { hidePrices(); setTimeout(function(){ showPrices(); }, 15000); setTimeout(function(){ hidePrices(); }, 30000); setTimeout(function(){ showPrices(); }, 50000); }

Did this answer your question?