I'm building an Question/Answer Application in which I generate the Questions and Answers from Oracle database.
I'd like to validate through javascript that the user should answer each question.
First, I iterate through the questions.
Then, inside each question, I check if the user has chosen an answer (If the radio button is checked). If not alert a message.
I get the answer through:
Expand|Select|Wrap|Line Numbers
- var ans_rdo = document.getElementsByName('answer'+i);
Expand|Select|Wrap|Line Numbers
- if(ans_rdo[j].checked == true)
Error: 'checked' is null or not an object
Here is the complete function:
------------------
Expand|Select|Wrap|Line Numbers
- function ValidateEntery()
- {
- var qst_cnt = Number(document.Form1.quest_count.value);//Number of Questions
- for(i=1; i <= qst_cnt; i++)
- {
- var chk_cnt = 0;//number of radio checked
- var ans_rdo = document.getElementsByName('answer'+i); //get the anser radio button
- for(j=1; j <= ans_rdo.length; j++)
- {
- if(ans_rdo[j].checked == true) // here I get this error: 'checked' is null or not an object
- {
- chk_cnt ++;
- }
- }
- if(chk_cnt <= 0)
- {
- alert("Please answer all questions");
- return false;
- }
- }
- }