Here is a simple methode for how to save php variable in a hidden input soyou can use later time after page load with javascript or jquery :
<input type="hidden" id="my_val" value="<?php echo $variable; ?>">
<input type="hidden" id="my_val" value="<?php echo $variable; ?>">