Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9158093
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T13:10:12+00:00 2026-06-17T13:10:12+00:00

I have several .js files each containing different functions and several HTML files showing

  • 0

I have several .js files each containing different functions and several HTML files showing different parts of the website. I declared a variable in main.js called var lang = “ENG”. However, this is the default language in case the user doesn’t select a language to change the content of the website. If I were to click a button in index.html:

<button id="french" onclick="changeLang('French')">French</button>

It should change the language of the var lang to “FRE” permanently for the rest of the current browsing period. I have tried using innerHTML, a click listener, a function returning the new value (i.e. var lang = setLanguage(inp), but nothing seems to work. Would anyone please give a suggestion on this? I am working off a large existing code database so I would like something that works in this context (currently not better ways of implementing a “language” facility in the website), although that would certainly be an improvement I would work on long-term. Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T13:10:14+00:00Added an answer on June 17, 2026 at 1:10 pm

    If I understand correctly, you want the information to persist even as new documents are loaded. There is no ‘duration of the program’ as far as each individual document is concerned, but you can store data across a session by writing and reading from the sessionStorage object.

    Set:

    sessionStorage.setItem('language', 'FRE');
    

    Get:

    var language = sessionStorage.getItem('language');
    

    You could also use cookies, which may be necessary if you need to support old timey browsers.

    Edit:
    On re-reading your question, I realized it sounds like you were unable to set the language variable at all, much less across the whole browser session. If that’s the case, I suspect you’re running into a variable scope problem. Maybe show us the changeLang function? For example if lang is declared at the global scope, the setting function should not use ‘var’ or else it will be creating a new variable with that name in its local scope only.

    var lang = 'ENG';
    function changeLang(newLang) { lang = newlang };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a project with several CSS files, each with many different settings. Every
I have hundreds of directories, each containing several zip files. I would like to
I have a directory containing hundreds of files (each having several chars). I want
We have many projects with several files inside each. Files can be checked in
I have several hundred files in a non-flat directory structure. My Makefile lists each
we have several tens of macro enabled excel files, each of those contains few
I have an iOS application with several controllers, each with their own xib files.
I have a text file with several different sections. Each section has a header
I have several xml files with different node structure. I want to extract xml
I have several files about 15k each of CSV data I need to import

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.