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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T14:57:23+00:00 2026-05-23T14:57:23+00:00

Rookie question: I have the following JavaScript functions. This works correctly but I don’t

  • 0

Rookie question: I have the following JavaScript functions. This works correctly but I don’t want to hardcode the strings “Names” and “namesDiv”. I want to pass them in as parameters to the getItems().How do I do this?

Edit: The function GetMsg() returns a JSON object: result.

HTML:

<input type="button" onclick="getItems(); return false;" value="Go"/>

JS:

function getItems() {
   loadingMsg();
   GetMsg("Names", null, callback);
}

function callback(result, args){
   clearContainer();
   //do stuff
   document.getElementById("namesDiv").append(foo);
}

function loadingMsg(){
    clearContainer();
    // do stuff
    document.getElementById("namesDiv").append(foo);   
}

function clearContainer(){
    document.getElementById("namesDiv").innerHTML = "";
}
  • 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-23T14:57:23+00:00Added an answer on May 23, 2026 at 2:57 pm

    For half of them, it’s obvious; you just start passing the parameters to the function:

    function loadingMsg(containerID) {
        clearContainer(containerID);
        document.getElementById(itemDiv).append(foo);   
    }
    
    function clearContainer(containerID) {
        document.getElementById(containerID).innerHTML = "";
    }
    

    callback is a little more complex. We’ll turn it into a function returning the callback.

    function makeCallback(containerID) {
        function callback(result, args) {
            clearContainer();
            document.getElementById(containerID).append(foo);
        }
        return callback;
    }
    

    Now we can call makeCallback to get a callback. We can now write getItems:

    function getItems(itemType, containerID) {
       loadingMsg(containerID);
       GetMsg(itemType, null, makeCallback(containerID));
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This may be a rookie question but if I have created a suite of
Okay this is probably a rookie question, but I have never done GUI programming
This is probably a rookie question but; Let's say I have an ActionResult that
This is obviously a rookie question about Adobe technologies, but I am seeking a
This is probably a rookie question, but I need to know what I need
Sorry that this may seem like a rookie question, but it's a real pain
I apologize for this, and I am sure it's a very rookie question... but
I know this is a really rookie question but would like some understanding off
I know this is a rookie question but whats actually happening with a progress
this might be a rookie question, but how would you efficiently apply regex expressions

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.