Wrox Home  
Search P2P Archive for: Go

  Return to Index  

javascript_howto thread: Dynamic checkbox validation


Message #1 by "Liliana Meneses" <menesesg@h...> on Tue, 12 Nov 2002 03:34:22 +0000
Hello all:
I am using the "beginning javascript" code for creating a quiz trivia, but in the book, radio buttons questions are created only, I
am using the same code of the radio buttons to create the checkboxes which code is:
questionHTML = questionHTML + "<P>" + questions[questionNumber][0];      questionHTML = questionHTML + "</P>";      for
(questionChoice = 1;questionChoice < questionLength;questionChoice++)      {         questionHTML = questionHTML + "<INPUT
type=radio "          questionHTML = questionHTML + "name=radQuestionChoice"         if (questionChoice == 1)         {           
questionHTML = questionHTML + " checked";         }         questionHTML = questionHTML + ">" +           
questions[questionNumber][questionChoice];         questionHTML = questionHTML + "<BR>"       }
Of course instead "<input type=radio"> I use <input type=checkbox>. 
My only problem is how can I know "which" checkboxes are "checked" so I can validate them with my answers array.
The code for radiobuttons validation is:
function getAnswer(){   var answer = 0;
    if (document.QuestionForm[0].type == "radio")   {      while (document.QuestionForm.radQuestionChoice[answer].checked !=
true)         answer++;         answer =  String.fromCharCode(65 + answer);   }  
   return answer;}
Please help me, I need help, I´ve working a lot in this without success. Please!!!!Help STOP SPAM with the new MSN 8  and get 2
months FREE*

  Return to Index