Javascript – Store a session variable in html/javascript

htmljavascriptPHPsession

I'm trying to grab a session variable in my javascript, but have some problems getting it right..
I didn't get that to work, so instead i tried to store it in a hidden variable in HTML first, but i dont know how to store a session variable there..
Can anyone guide me to the right path?

The code (HTML file): ($_SESSION["price1"] is equal to "20.00")

<input type="hidden" id="price" value="$_SESSION["price"]"/>

The code in javascript:

    var sessionValue = document.getElementById("price").value;

What to do?

Best Answer

you missed PHP tags <?php and echo, change to:

<input type="hidden" id="price" value="<?php echo $_SESSION["price"]; ?>"/>