Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 2nd, 2012  |  syntax: None  |  size: 1.14 KB  |  hits: 17  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. getting input from last input-areas in an array of dynamically generated text inputs
  2. var NumberOfQuestions= 10;
  3.     var questionCounter = 1;
  4.     var score=0;
  5.  
  6.     //create the Problem array
  7.     var QuestionArray = [];
  8.     QuestionArray.push(0);
  9.     for (i=1; i<=NumberOfQuestions; i++){
  10.         var randomNumber = Math.floor(Math.random()*110);
  11.         QuestionArray.push(randomNumber);
  12.         }//end for loop
  13.  
  14.  
  15.  
  16.     $(function() {
  17.     $("#ok").click(function() {
  18.         if(questionCounter <= NumberOfQuestions){
  19.             $("#ok").after("<p>" + QuestionArray[questionCounter]  + "<input type='text' size='1' class='r'/></p>");
  20.             questionCounter++;}//end if
  21.           var temp = (".r").value();
  22.           $("#hg").append(temp);        
  23.         });//end click function
  24.     });
  25.  
  26.  
  27. });
  28.        
  29. $(function() {
  30. $("#ok").click(function() {
  31.     var temp = $(".r").last().val();
  32.     $("#hg").append(temp);
  33.     if(questionCounter <= NumberOfQuestions){
  34.         $("#ok").after("<p>" + QuestionArray[questionCounter]  + "<input type='text'          size='1' class='r'/></p>");
  35.         questionCounter++;}//end if              
  36.     });//end click function
  37. });