I am a beginner in php and javascript I am using a session variable to hold a counter on next button click i want to increment the counter and on prev button click i want to decrement the counter and i want to reload the page later , the problem is with self invocation of the javascript function without being called by the button click. This makes both f1 and f2 to be called nullifying the counter value. I want to prevent self invoking.
<button type="button" onClick="f1();" id="prev"><< Prev</button>
<button type="button" onClick="f2();" id="next">Next >></button>
<script>
function f1(){
<?php $_SESSION['counter']= $_SESSION['counter']-1?>
window.location.reload();
}
function f2(){
<?php $_SESSION['counter']= $_SESSION['counter']+1?>
window.location.reload();
}
</script>
Thank you.
sessionStorageinstead, you can achieve the same result with pure Javascript.