473,414 Members | 1,750 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,414 software developers and data experts.

Problem when to iterate through Radio Buttons

24
Dear All,

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
  1. var ans_rdo = document.getElementsByName('answer'+i);
but, when I iterate through it to check if it's checked or not:
Expand|Select|Wrap|Line Numbers
  1. if(ans_rdo[j].checked == true)
I get this error:
Error: 'checked' is null or not an object

Here is the complete function:
------------------

Expand|Select|Wrap|Line Numbers
  1. function ValidateEntery() 
  2. {
  3.     var qst_cnt = Number(document.Form1.quest_count.value);//Number of Questions
  4.  
  5.     for(i=1; i <= qst_cnt; i++)
  6.     {
  7.         var chk_cnt = 0;//number of radio checked
  8.         var ans_rdo = document.getElementsByName('answer'+i); //get the anser radio button
  9.         for(j=1; j <= ans_rdo.length; j++)
  10.         {
  11.             if(ans_rdo[j].checked == true) // here I get this error: 'checked' is null or not an object
  12.             {
  13.                 chk_cnt ++;
  14.             }
  15.         }
  16.  
  17.         if(chk_cnt <= 0)
  18.         {
  19.             alert("Please answer all questions");
  20.             return false;
  21.         }
  22.  
  23.     }        
  24. }
--------------------------
Oct 26 '11 #1

✓ answered by Dormilich

the error implies that the fetched object is not a radio button (or checkbox). there might be another form element with that name.

2 1854
Dormilich
8,658 Expert Mod 8TB
the error implies that the fetched object is not a radio button (or checkbox). there might be another form element with that name.
Oct 27 '11 #2
goodamr
24
Thank you Dormilich for replying.

You are correct but the problem is because I have iterated through the radio buttons from 1:

Expand|Select|Wrap|Line Numbers
  1. for(j=1; j <= ans_rdo.length; j++) 
I should begin the iteration from 0 like that:

Expand|Select|Wrap|Line Numbers
  1. for(j=0; j < ans_rdo.length; j++) 
So the prblem has been solved.
Oct 28 '11 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Suzanne | last post by:
Hi, I have a form which our clients can fill in with their personal details. As part of the information we store there is a section - areas of interest - this is a number of radio buttons. ...
2
by: Jeff | last post by:
I'm trying to create a dynamic form that can have multiple groups of radio buttons (each group has two buttons) with the same name. Essentially, the form allows a user to enter as many names as...
1
by: imjess | last post by:
Hi, I'm having a problem binding two radio buttons to a dataset. Seems that the radio buttons are visually updated, but the corresponding values are not updated in the dataset. I have many...
1
by: momo | last post by:
Hello all, I need some help with radio buttons. This is what I have. I have 15 groups of radio buttons and each group contains three radio buttons which non of them are selected. I need a way...
3
by: Ken Varn | last post by:
This is probably a simple question, but I am new to this so bear with me. I have a ASP.NET form that has a checkbox and a 2 radio buttons. When the checkbox is checked, the 2 radio buttons are...
3
by: Michael Hesse | last post by:
Hi, I have an application with 177 radio buttons on a screen (Don't ask!). Is there a simple want to excute a sub when any of them are checked. Thanks, Michael
3
by: Syswatch | last post by:
Hi out there... I am pretty new to javascript, and is looking for some help here. I have a problem, I need a small javascript, which checks if there is any text in my textarea, and if it is NOT...
2
by: dpazza | last post by:
Hi, I'm creating a quiz on using a form in VB 2005 express. I have four sets of questions and answers (labels and radio buttons) and I change between which set of questions is currently shown on...
7
by: moksha | last post by:
Hi, I am new to javascript and i am facing a problem in coding. plz help me out. I am using javascript for dynamically creating a table row which contains text boxes and radio...
11
by: Twayne | last post by:
Hi, Newbie to PHP here, no C or other relevant background, so pretty niave w/r to the nuances etc. but I think this is pretty basic. XP Pro, SP2+, PHP 4.4.7, XAMPP Local Apache Server...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.