NetTalk Central

Author Topic: Getting session variable in javascript  (Read 3265 times)

Ubaidullah

  • Full Member
  • ***
  • Posts: 125
    • View Profile
Getting session variable in javascript
« on: February 22, 2021, 08:36:35 PM »
Hi Bruce,

I have a custom javascript file which displays some values on a NetWebForm.

Now, I need to use the session variable "language" to determine which values to display.

Since I cannot access the session variable from inside javascript, what would be the best way to get the value of "language" for my javascript code?

Thanks
&
Regards,
Ubaidullah Nubar.

Bruce

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 11250
    • View Profile
Re: Getting session variable in javascript
« Reply #1 on: February 22, 2021, 10:25:44 PM »
a) add a function to your custom JavaScript to set a global JavaScript variable;
b) call the function from your program;

var globalLanguage='';
function setLanguage(lang){
  globalLanguage = lang
}


then in your code somewhere
p_web.Script('setLanguage("' & p_web.GSV('lang') & '");')

Ubaidullah

  • Full Member
  • ***
  • Posts: 125
    • View Profile
Re: Getting session variable in javascript
« Reply #2 on: February 24, 2021, 07:10:08 PM »
Thanks Bruce.

That worked well.

Regards,
Ubaidullah Nubar.