I am using the following code without a problem to scroll to an HTML element.
<?php
if ($_SESSION['id']=="bed5") {
?>
<script>
document.getElementById('bed5').scrollIntoView(true);
</script>
<?php
}
?>
However I want to destroy the SESSION['id'] after the JS has scrolled to the HTML just ONCE in order to prevent the page repeatedly navigating to the scroll view. So at the end of my script after the JS above I have added.
<?php
unset($_SESSION['id']);
?>
However the addition of the UNSET function after the JS above is causing the JS to fail. Ie it does not scroll to view the HTML element...even just the once....as I had expected. In summary I just need to get the JS to render a single scroll event .... conditional on the session variable...ONCE.
Anyone know what I am doing wrong here and how to solve the problem please?