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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T10:46:36+00:00 2026-06-17T10:46:36+00:00

These forums are amazing and the contributors I’ve been helped by are really talented.

  • 0

These forums are amazing and the contributors I’ve been helped by are really talented. So I keep coming back everytime I can’t solve my own problems or am not understanding a programming concept. This is certainly one of the latter times!

With the help I’ve received so far, I’ve managed to develop a complicated form in which the end user will mostly click a series of checkboxes and enter some data into a few textfields. The result of these actions will populate some textboxes with various text, based on the aforementioned actions.

The text that populates the textareas is referenced within a few object literals by each checkbox. This works just fine and the site is quite useable.

In my object literals, I have name:value pairs in which the ‘value’ is a string of text. I’ve been trying to include a variable within some name:value pairs to no success. This always breaks the script because the variable is never defined / has a ‘null’ value on page load.

For example,

Instead of

    var example = {
var1:'some string',
var2:'some other string'
  }

I tried,

var somevariable = document.getElementById('someId');
var example = {
var1: 'some string' + somevariable + 'some other bit',
var2: 'some other string'
}

My question is whether including a variable referenced elsewhere in the script can be incorporated within the name:value pair in an object literal?

For reference (and because it is a rather long script), my site is: http://www.hematogones.com/bmbiopsies.html.

  • 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-17T10:46:37+00:00Added an answer on June 17, 2026 at 10:46 am

    The trick with an object literal is that it is evaluated immediately; there is no “easy” way to delay the value you get.

    var x = "Alice";
    var obj = { greeting: "Hello, " + x + "." };
    console.log(obj.greeting);  // "Hello, Alice."
    x = "Bob";
    console.log(obj.greeting);  // "Hello, Alice."
    obj = { greeting: "Hello, " + x + "." };
    console.log(obj.greeting);  // "Hello, Bob."
    

    Something to come back to later:

    If you really really really need to put a variable into a string literal you define later, you could create an inline function. This way, instead of obj.greeting being a simple string, it is a function that you call (which will look like obj.greeting()).This means that instead of the string value being calculated when you declare your object, it will be declared when you call the function. This is a very powerful feature of Javascript called “closures” and you could spend all day learning about the behaviors, expected and unexpected, that you get with them.

    var x = "Alice";
    var obj = { greeting: function() { return "Hello, " + x + "." }};
    console.log(obj.greeting());  // "Hello, Alice."
    x = "Bob";
    console.log(obj.greeting());  // "Hello, Bob."
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been searching these forums, but also the web at large. Can you
I have been reading these forums for some time, but this is my first
forumcats: id, name forums: id, name, cat_id How can i join these together and
I've been roaming around these forums asking questions about issues related to Python and
I have been searching all over the apple documentation, including these forums, yet was
Super newb here. Been searching for 4 hours on google and these forums and
How can I implement these scenarios using forms authentication? If the user is Inactive
We have Win Forms application uses the 3rd party windows native controls. Can these
I usually don't post questions on these forums, but I've searched all over the
I'm new here, just found these forums on Google. First of all, I want

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.