At first i am not sure if using cookies is the right way.
What i basically need is a variable that i store from one page , and then to use it on another page.
If it can be done without cookies then its great , if not then i will just have to do it with cookies.
For setting cookies within JavaScript have a look at here.
Remember, that the data you store in cookies is transmitted with every request for that page or domain. So if you want to store larger amounts of data, maybe local storage is more suitable.