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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T00:34:05+00:00 2026-05-26T00:34:05+00:00

I have a collection of strings which I want to select from to insert

  • 0

I have a collection of strings which I want to select from to insert text into a page.

The strings are stored in an object/array, like so:

var strings = {
    x01: 'Hello world',
    x02: 'Goodbye world'
    x03: 'The quick brown fox',
    x04: 'jumped over'
    x05: 'the lazy dog',
    x06: 'the fat lady sung'
};

In my HTML, I have span tags that have IDs that correspond to the variables above.

However, on any one page, only some of the spans will show up at any one time. So, for example, there might be only three of them:

<span id="x01"></span>
<span id="x04"></span>
<span id="x06"></span>

What I want to do is be able to search the page to gather up all the IDs that match the naming convention (x followed by two digits), and then match them to the corresponding variable so that I can fill the span with the appropriate text.

Something like (this is a rough outline, not meant to be taken as actual code):

array = getElementsByID(someKindOfMultipleSelect);
for (var key in array)
{
   document.getElementById(**IDandVarName**).innerHTML = strings.**IDandVarName**;
}

Despite doing some Googling on this, I’m stuck on two points. I don’t know how to gather the span IDs I want from the page, and I don’t quite know how to match them up once I’ve got them.

Yes, I’m kind of a noob at Javascript, so please be gentle with me in explaining this.

Thank you for any advice.

  • 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-05-26T00:34:06+00:00Added an answer on May 26, 2026 at 12:34 am

    Below is a pure (and very simple) JavaScript solution. This solution avoids gathering up all the spans on the page (not efficient), and grabs the elements by ID only.

    HTML:

    <span id="x01"></span>
    <span id="x04"></span>
    <span id="x06"></span>
    

    JavaScript:

    var strings = {
        x01: 'Hello world',
        x02: 'Goodbye world',
        x03: 'The quick brown fox',
        x04: 'jumped over',
        x05: 'the lazy dog',
        x06: 'the fat lady sung'
    };
    
    for (var key in strings) {
        var obj = document.getElementById(key);
    
        if(obj)
            document.getElementById(key).innerHTML = strings[key];
    }
    

    Here’s a working fiddle.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Dictionary<int, string> which I want to take the Key collection into
I have a collection of strings. I need to find out from this collection
I have a simple json string which contains a collection of objects http://sandapps.com/InAppAds/ads.json.txt When
I have a Person class which has a String collection of aliases representing additional
I have a C# list collection that I'm trying to sort. The strings that
I have a collection of string. I want to create an image out of
I have a collection of objects stored in a CollectionViewSource and bound to a
I have a table like this. Columns --> (MUSTERI, AVUKAT, HESAP (Unique)) My page
I am currently using VB. I want to do a Calendar Control which have
I have a collection of records. Which have two boxers, match date, location etc...

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.