Need to Convert JavaScript Session Variable to VB Classic ASP

I need a way to modify the code below so that I can set it via VB with Classic asp. Currently it works with java Script, however users with Java Script Turned off loose the functionality. If I change it to VB and Server Side it should work for those users.

<script type="text/javascript">document.cookie='userLanguage=<%=Session("userLanguage")%>'</script>
Who is Participating?
FreakyEddieConnect With a Mentor Commented:
To set it:

To retrieve it:
strRetrieveUserLanguage = Request.Cookies("userLanguage")

You can use the cookies when you want it to be stored for a longer time. When you just want the lifetime of a browser-session, you can use sessions.
You're allready doing so by using Session("userLanguage")

You set it with
Session("userLanguage") = 1043


Retrieve it with
strUserLanguage = Session("userLanguage")
DakotaKatAuthor Commented:
Is there a way I can write the cookie then with out using JavaScript?
What Kind of Coding Program is Right for You?

There are many ways to learn to code these days. From coding bootcamps like Flatiron School to online courses to totally free beginner resources. The best way to learn to code depends on many factors, but the most important one is you. See what course is best for you.

To write the cookie type in your webpage-code:

Session("userLanguage") = 1043 'for USA

Else please post a bit more code or explain a bit more in how you're using it.
DakotaKatAuthor Commented:
I have a language selector that works for everyone with Javascript enabled, but for those who have it turned off they can not write the cookie that is read each time a page it loaded to determine the correct language. Below is the code on the current page.

<% If (Instr(Session("pageLanguages"), "US") > 0) Then %>
            <a title="ENGLISH" style="text-decoration:none" href="<%=Request.ServerVariables("SCRIPT_NAME") & nQueryString%>lang=us">
            <img src="images/flags/en.png" alt="ENGLISH">&nbsp;English</a>
            <script type="text/javascript">document.cookie='userLanguage=<%=Session("userLanguage")%>'</script>

I would like to be able to set that document.cookie value using something serverside if possible. I know it will not solve my problem if they have cookies turned off.
DakotaKatAuthor Commented:
Thanks so much FreakyEddie
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.