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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T08:17:54+00:00 2026-06-11T08:17:54+00:00

I’ll start by explaining what is it that I’m trying to do :) My

  • 0

I’ll start by explaining what is it that I’m trying to do 🙂

My application is implemented using PHP (Zend framework) and Javascript. I want to make a questionnaire for my application and so far I have done the following:

My page consists of series of <div class='question #'> elements where # denotes the index of the spesific question. For example my HTML looks like this:

<div class="question 1 active">
</div>
<div class="question 2">
</div>
<div class="question 3">
</div>
.
.
.
etc.

Now the user should see each question for a spesific pre-selected time until the question changes into the possible answer and the user should click either “Yes” or “No” depending if he thinks the answer is correct. Only one <div class="question #">-element is active at a time, the others have display:none;. After the question is changed to the next one, the active-attribute is removed from the current question and set to the next one so the user loops through all the questions.

With each question/possible answer-pair I have associated two integers which spesify how long the user has time to see the question and how long the user has time to answer the question. Let me give an example:

The user sees this (more or less):

QUESTION 1/10

The name of the President of U.S.? -------------- 5 sec 
..
The name of the President of U.S.? -------------- 4 sec
..
The name of the President of U.S.? -------------- 3 sec
..
etc. THE TIME ENDS and the question changes to answer mode(buttons YES/NO appear also in this part):

Bruce Wayne? ------------------------------7 sec 
 [YES] [NO]  
...
Bruce Wayne? ------------------------------6 sec 
 [YES] [NO]  
...
Bruce Wayne? ------------------------------5 sec 
 [YES] [NO]  
...
etc. 

When either the time runs out in the ANSWER-phase OR the user clicks either of the buttons YES/NO jQuery removes ACTIVE from current question and sets it to the next one. The value the user clicked is also stored in hidden-element. This process should be repeated all the way through the questionnaire.

Now about the timers of both the question and answer phase. They are NOT fixed but spesified for each question. For example question1 might have question/answer times (in seconds) 5/10 and so forth.

Now my question is…how to implement this in the javascript side??? My problem comes in when I loop in javascript through the array which contains all the information regarding the questions (which PHP sets in server)…I should be able to iterate through all question/answer-pairs in client-side and then on each iteration stop the iteration from moving on to the next one (next question) until the user has clicked answer or the time has run out. But the problem is as I understood that I CANNOT sleep in the for-loop or in .each in jQuery…Do you see my problem? 🙂

Any suggestions on implementation 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-06-11T08:17:56+00:00Added an answer on June 11, 2026 at 8:17 am

    Change the for loop to a recursive function called via a setTimeout

    var timeLeft = 10,
        countdown = function(){
            $('#mySpan').html('The name of the President of U.S.? -------------- ' + timeLeft + ' sec');
            timeLeft -= 1;
    
            if (timeLeft) {
                setTimeout(countdown, 1000);
            }
        };
    
    countdown();
    

    Take that logic and you can extend it to change your question after X seconds and so on, and then you can scale it by taking in parameters like maxTime, questionText, and questionType to display an input field or set of radio buttons for example.

    Quick demo: http://jsfiddle.net/AlienWebguy/aW9mH/

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

Sidebar

Related Questions

I'm trying to create an if statement in PHP that prevents a single post
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want to count how many characters a certain string has in PHP, but
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am reading a book about Javascript and jQuery and using one of the
I have a French site that I want to parse, but am running into
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I am trying to render a haml file in a javascript response like so:
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
link Im having trouble converting the html entites into html characters, (&# 8217;) i

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.