views:

44

answers:

1

am basically looking for a way in jquery where my script will wait 15seconds or so, and display a correct ans if the user hasnt selected an answer already. at the moment it just seems to run straight through. ps this method is called in a for loop, with other methods/functions so it runs straight through iterating through the array. thr for loop is placed below although appears further up in the actual script. to be clear am looking for a wa for the script to check if within those 15seconds the user has clicked a button. at the moment its not even doing that. there are about 10 items in the array, but once the start button is clicked to start the quiz it iterates straight through right to the last item, so the user doesnt even get to make a choice. setTimeout i dont think i appropriate here...tried it but theres a huge poss i cld be wrong

function getUserResp(){
     $("#countdown").countdown({seconds: 15});

    setTimeout("dispAns()", 16000);

    $("#ans1").click(function(){
      ansStr=$(this).text();
      checkAns(ansStr);
      });    
    $("#ans2").click(function(){
      ansStr=$(this).text();
      checkAns(ansStr);
      });    
    $("#ans3").click(function(){
      ansStr=$(this).text();
      checkAns(ansStr);
      });

 $(".ans").mouseover(function(){
      $(this).addClass("hilite").fadeIn(800);
      });  

 $(".ans").mouseout(function(){
        $(this).removeClass("hilite");
        });

}

 $.each(qArr, function(i){
   getAns(i);
   getQuestion(i);
   presentData();
   getUserResp();
   displayAnsResp();
 });
 getTotalScore();
 });
+1  A: 

setTimeout is the way to go,. you can have the function called after 15 seconds using setTimeout and then the function should check if any button has been pressed,. if no it should display the answer,,. you can set a flag to true when any button is clicked and then check that flag in the displayanswer function

ovais.tariq