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 9164721
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T14:45:00+00:00 2026-06-17T14:45:00+00:00

I have a set of defined variables. I dynamically set a value to another

  • 0

I have a set of defined variables. I dynamically set a value to another variable that ends up being the name of one of the other defined variables. I want to do this so I know when on the page to use which of the set variables.

var mwm = "blah"
var vp = "bleh"
var am = "bluh"

var mwm720 = "some link 1"
var mwm717 = "some link 2"
var vp720 = "some link 3"
var vp717 = "some link 4"
...

Then I have some other scripts that run and, depending on conditions, sets a variable value to be the name of one of the other variables.

var myClass = $(this).attr("class").split(' ')[1];
var currDiv = "div." + myClass;
var currVersion = $(this).parent().attr("id");
var linkVers = myClass + currVersion;

The linkVers variable value always ends up being "mwm720", "mwm717", "vp720", etc. That’s how I know when to use the mwmw720 or mwm717 (etc) variables.

Desired behavior

How do I get an alert/call to use the value of the variable name that is stored in the dynamic variable?

Let’s say alert(linkVers); returns "mwm720". How do I get $(currDiv).html(linkVers); to insert the value of the mwm720 variable, (which would be "some link 1"), and not the name of the variable?

If there’s a better method for trying to accomplish this behavior, I’ll certainly entertain other solutions.

  • 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-17T14:45:01+00:00Added an answer on June 17, 2026 at 2:45 pm

    You should put all your vars within 1 object. Like:

    var messsages = {
        wm : "blah",
        p : "bleh",
        m : "bluh",
    
        wm720 : "some link 1",
        wm717 : "some link 2",
        p720 : "some link 3",
        p717 : "some link 4"
    }
    

    Then within your function you can use

    alert(messages[linkVers]);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a set of variables that i need for multiple other classes. I
I have a set of variables S , and a boolean function f defined
I have set JAVA_HOME = C:\Program Files\Java\jdk1.6.0_26 in user defined variables and system variables
I have a list of buttons in one of my activities that are dynamically
Is there a way to get a list of user-defined variables that have a
I have a TARGET variable that can be set to dev, test or prod.
I have member variables in my custom UIViewController that are defined as 'assign' (not
Suppose that I have a lot of variables defined in my code with names
I have a variable define as: set filePath=.\file.txt I'm writing a windows batch file.
I have a set S of points (2D : defined by x and y)

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.