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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T05:09:42+00:00 2026-05-18T05:09:42+00:00

So I am trying to make a string out of a string and a

  • 0

So I am trying to make a string out of a string and a passed variable(which is a number).
How do I do that?

I have something like this:

function AddBorder(id){
    document.getElementById('horseThumb_'+id).className='hand positionLeft'
}

So how do I get that ‘horseThumb’ and an id into one string?

I tried all the various options, I also googled and besides learning that I can insert a variable in string like this getElementById("horseThumb_{$id}") <– (didn’t work for me, I don’t know why) I found nothing useful. So any help would be very appreciated.

  • 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-18T05:09:42+00:00Added an answer on May 18, 2026 at 5:09 am

    Your code is correct. Perhaps your problem is that you are not passing an ID to the AddBorder function, or that an element with that ID does not exist. Or you might be running your function before the element in question is accessible through the browser’s DOM.

    Since ECMAScript 2015, you can also use template literals (aka template strings):

    document.getElementById(`horseThumb_${id}`).className = "hand positionLeft";
    

    To identify the first case or determine the cause of the second case, add these as the first lines inside the function:

    alert('ID number: ' + id);
    alert('Return value of gEBI: ' + document.getElementById('horseThumb_' + id));
    

    That will open pop-up windows each time the function is called, with the value of id and the return value of document.getElementById. If you get undefined for the ID number pop-up, you are not passing an argument to the function. If the ID does not exist, you would get your (incorrect?) ID number in the first pop-up but get null in the second.

    The third case would happen if your web page looks like this, trying to run AddBorder while the page is still loading:

    <head>
    <title>My Web Page</title>
    <script>
        function AddBorder(id) {
            ...
        }
        AddBorder(42);    // Won't work; the page hasn't completely loaded yet!
    </script>
    </head>
    

    To fix this, put all the code that uses AddBorder inside an onload event handler:

    // Can only have one of these per page
    window.onload = function() {
        ...
        AddBorder(42);
        ...
    } 
    
    // Or can have any number of these on a page
    function doWhatever() {
       ...
       AddBorder(42);
       ...
    }
    
    if(window.addEventListener) window.addEventListener('load', doWhatever, false);
    else window.attachEvent('onload', doWhatever);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to make a method that returns a string of words in opposite
.NET balanced group regexes make my head explode. I've got this string i'm trying
I'm trying to make a program that check the ISBN number and sees if
Trying to make a make generic select control that I can dynamically add elements
I'm trying to make a context menu for a control that is linked to
I am trying to make a div, that when you click it turns into
I'm trying to make a method that will tell me weather or not it
Alright, so I'm trying out C++ for the first time, as it looks like
I am trying to make a BigDecimal from a string. Don't ask me why,
I am trying to make this VideoView to appear in full screen mode :

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.