Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

222
Views
javascript how to get the web page get Session variable

I'm trying to use a Session variable in javascript.

I have tried a number of post suggestions without success unfortinately.

I see this example all over the place.

    var userName = '<%= Session["UserName"] %>'

However that is not working, at least for me. What I am trying to do is as below.

    var qrdataString = "<qr-code data=" + "XL" + ' <%= Session["style"] %>'  + "></qr-code>";
    document.getElementById("styleqr").innerHTML = qrdataString; 

Using Single quotes where they appear above just returns the string as

    <%=Session["xUID"]%>   in the alert that I use to show me the returned value

Using Double quotes give me either - unexpected token: string literal - or unexpected token identifier.

Thanks

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

After messing around for a while, and also stumbling on the following article, I have managed to get this going.

    https://newbedev.com/get-current-session-value-in-javascript 

FULL RESULT

HTML

    Dim xstyle: xstyle = session("style")

    <div class="hr">
      <input type="hidden" id="hdnSession" data-value= <%= xstyle %> />
    </div>

JAVASCRIPT

    var hdnString= $("#hdnSession").data('value');
    var qrdataString = "<qr-code data= " + hdnString  + " ></qr-code>";
    document.getElementById("qrcode").innerHTML = qrdataString;

HTML

    <div class="panel-body" id="qrcode">
        javasctipt inserts the html here  <!--qr-code data="test"></qr-code -->
    </div>
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!