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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T05:50:26+00:00 2026-06-11T05:50:26+00:00

I have some sample data like so: var data = { section: { 1:

  • 0

I have some sample data like so:

var data = {
    "section": {
        "1": {
            "question": [{
                "id": "1a",
                "num": "1",
                "title": "test"
            }, {
                "id": "1b",
                "num": "2",
                "title": "test"
            }]
        },
        "2": {
            "question": [{
                "id": "2a",
                "num": "1",
                "title": "test"
            }, {
                "id": "2b",
                "num": "2",
                "title": "test"
            }]
        }
    }
}

Using this I’m attempting to count the number of questions. So for this sample of data that would be 4 questions in total…

The plan is to update a progress meter width using this data:

<div id="progress"><div id="bar"></div></div>

Here is the JS code I have started putting together:

var number = 0, numQuestions, total, width;

function updateProgress() {

    number += 1;

    numQuestions = data.question;

    //total =

    width = total / number;

    $('#progress #bar').animate({'width':width});

}

To get the width I’m guessing that I’d need to add BOTH sections and questions together and divide it by the width of the progress bar and then set the width of the progress as the number of that number??

Can anyone give some help and point me in the right direction?

The main issues are:

  • numQuestions is returning undefined, so obviously I’m doing it wrong
  • I’m not sure how to work out the total… should this be the #progress #bar width calculated against the numQuestions? Or something else entirely?
  • 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-11T05:50:27+00:00Added an answer on June 11, 2026 at 5:50 am

    I would recommend modifying your data structure as follows:

    var data = {
        "sections": [ // sections is now an array instead of an object
            {
                "question": [{
                    "id": "1a",
                    "num": "1",
                    "title": "test"
                }, {
                    "id": "1b",
                    "num": "2",
                    "title": "test"
                }]
            },
            {
                "question": [{
                    "id": "2a",
                    "num": "1",
                    "title": "test"
                }, {
                    "id": "2b",
                    "num": "2",
                    "title": "test"
                }]
            }
        ]
    }
    

    Unless you need to name the sections, there is no need to key them.

    You can then grab the number of sections like so:

    var numSections = data.sections.length;

    To get the total number of questions in all sections, you’ll need to create a loop:

    var numQuestions = 0;
    for (var i = 0; i < data.sections.length; i++){
        var questions = data.sections[i].question;
        for (var j = 0; j < questions.length; j++){
            numQuestions++;
        }
    }
    

    Then, to update the progress bar you would:

    function updateProgress() {
        number++;
        width = number / numQuestions * 100;
        $('#progress #bar').animate({'width':width + '%'});
    }
    

    You’ll want #progress to have a set width, and #bar to have a percentage based width ranging from 0 to 100%.

    If you need to name the sections, you can count the number of questions like so:

    var numQuestions = 0;
    for (var sect in data.section){
        var questions = data.section[sect].question;
        for (var j = 0; j < questions.length; j++){
            numQuestions++;
        }
    }
    

    You can see all of this working here: http://jsfiddle.net/wAGHS/1/

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

Sidebar

Related Questions

I have a php program where I just test some sample data. I am
I have some data in .cvs. I would like to make a simple barplot
So I have a few properties that I'm using in some sample code I'm
Apologies for the essay-like nature of this question. I have been struggling to get
Let's say I have some simple data y = [[datetime.datetime( 2012,1,1,1,1), 2.1], [datetime.datetime( 2012,1,1,1,2),
I'm new to WCF data services. I have a quite simple data model. Some
I have a simple jasper report which shows some data from database. The jasper
i have a simple template that i populate with some data then im trying
Say you have a simple class with some storage data structure (list, vector, queue,
I have written some sample program and DLL to learn the concept of DLL

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.