---
title: "get a session variable using java script function?"  
description: "get a session variable using java script function?"  
author: "marcel ethan"  
published: 2014-11-01  
updated: 2014-11-01  
canonical: https://www.mindstick.com/forum/2486/get-a-session-variable-using-java-script-function  
category: "javascript"  
tags: ["session", "session variable"]  
reading_time: 1 minute  

---

# get a session variable using java script function?

It may look like a stupid [question](https://www.mindstick.com/blog/23175/how-to-solve-neet-question-paper-in-less-time), but I went through various pages since 2 [days](https://www.mindstick.com/articles/157271/how-to-get-cloudways-free-trial-for-14-days-free), and didn't get to a solution by myself. So I made a [session variable](https://www.mindstick.com/forum/12804/how-to-set-a-asp-dropdownlist-selectedvalue-to-a-session-variable) like this:

```
<?php
session_start();

$_SESSION['currentpage']="home";
?>
```

(I checked, it does make the variable and assign it right.)

Then I tried to use it as a [parameter](https://www.mindstick.com/blog/450/parameter-class-in-c-sharp) here:

`<body onload="changepage($_SESSION['currentpage'])">`

It doesn't pass the variable. I tried to [put](https://answers.mindstick.com/qa/111890/can-you-explain-the-difference-between-put-and-post-http-methods) it into directly the [function](https://www.mindstick.com/articles/13001/multi-statement-table-valued-user-defined-function-in-sql-server), like not as a parameter, but inside it, doesn't work.

## Replies

### Reply by Jayden Bell

## You are missing the PHP tags:

<a onclick="window.open('../../Process.aspx','cal','width=490,height=420,left=500,top=180,scrollbars=no')"

href="javascript:;"><img alt="Process" src="../../images/register.gif" style="border-top-style: none; border-right-style: none; border-left-style: none; border-bottom-style: none" id="IMG1" onclick="return IMG1_onclick()" /></a>

<script type="text/javascript" src="../../NoPostBacks.js">

function IMG1_onclick() {

[Session](https://www.mindstick.com/articles/12042/session-in-c-sharp)("Amount") = Me.txtAmount.Text

Session("Zip") =Me.txtZip.Text

}

</script> - See more at: http://codeverge.com/asp.net.state-management/how-can-i-set-session-variables-with/307701#sthash.c0pM4q7S.dpuf

```
<body onload="changepage('<?php echo $_SESSION['currentpage']; ?>')">
```


---

Original Source: https://www.mindstick.com/forum/2486/get-a-session-variable-using-java-script-function

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
