472,993 Members | 2,001 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

JS error: form.elements[...].checked is null or not an object


I am facing a js error in my code, below is the prob. statement

I have a radio2 javascript function as below, it works like this..
When a parent radio button is selected only one of its child radio button can be selected and on selection of a new child button(of the same parent) the earlier child button is deselected.

When i navigate to this particular page and select a parent and select a child, when i select another child of the same parent the radio is selected( this should not have been the behaviour) and the below error is displayed:
form.elements[...].checked is null or not an object.

The js pop-up says the below line is the error(line marked in bold in source code):

My javascript code:

Expand|Select|Wrap|Line Numbers
  1. function sL_radio2_onclick(thisObj, thisEvent) {
  2. //use 'thisObj' to refer directly to this component instead of keyword 'this'
  3. //use 'thisEvent' to refer to the event generated instead of keyword 'event'
  4. // find the parent array number
  5. var indexStart = eval("form1:table1:".length);
  6. var indexEnd = thisObj.name.indexOf(':table2');
  7. var parentIndex = thisObj.name.substring(indexStart,indexEnd);
  8. // check the parent if child is checked and parent is not checked before
  9. parentRadioButtonName = 'form1:table1:'+parentIndex+':radio1';
  10. if (thisObj.checked && (!thisObj.form.elements[parentRadioButtonName].checked)) {
  11. thisObj.form.elements[parentRadioButtonName].checked=true;
  12. //uncheck other parent
  13. for(i=0;1==1;i++){
  14. parentRadioButtonName = 'form1:table1:'+i+':radio1';
  15. if (thisObj.form.elements[parentRadioButtonName]) {
  16. //if this parent is checked and not the parent of current child
  17. if(thisObj.form.elements[parentRadioButtonName].checked && (i != parentIndex)){
  18. thisObj.form.elements[parentRadioButtonName].checked=false;
  19. //uncheck children of this parent
  20. for(j=0;1==1;j++){
  21. childRadioButtonName = 'form1:table1:'+i+':table2:'+j+':radio2';
  22. if(thisObj.form.elements[childRadioButtonName]){
  23. thisObj.form.elements[childRadioButtonName].checked=false;
  24. } else {
  25. break;
  26. }
  27. }
  28. }
  29. } else {
  30. if (i>parentIndex) {
  31. break;
  32. }
  33. }
  34. }
  36. }
  37. //if this child is checked, uncheck other children 
  38. // which has same parent as this child
  39. if (thisObj.checked) {
  40. for(i=0;1==1;i++){
  41. childRadioButtonName = 'form1:table1:'+parentIndex+':table2:'+i+':radio2';
  42. if(thisObj.form.elements[childRadioButtonName]){
  43. //check this child is not itself
  44. if (!(thisObj.form.elements[childRadioButtonName]==thisObj)) {
  45. thisObj.form.elements[childRadioButtonName].checked=false;
  46. }
  47. } else {
  48. break;
  49. }
  50. }
  51. }
  52. }
JSP call:

Expand|Select|Wrap|Line Numbers
  1. <h:selectOneRadio styleClass="selectOneRadio" id="radio2"
  2. value="#{pc_SL.objectSpace.sPd}"  
  3. onclick="return sL_radio2_onclick(this, event);">
  4. <f:selectItem
  5. itemValue="#{varBObj.OrgBObj.sSId}"
  6. itemLabel=" " />
  7. </h:selectOneRadio>
Thanks in advance.
Nov 26 '07 #1
2 7256
Death Slaught
1,137 1GB
Not completely sure what it is you're trying to do.

However if you're trying to get/manipulate the value of a radio button depending on wether it is checked or not, that I can do.

Here's an example:


<script type="text/javascript">

function check() {
/* theCorrect is going to store the
correct answer's value */
/* theValue is going to store the
value of the user's input */
/* response is going to be the
computer's output */
var theCorrect;
var theValue;
var response;
//The for loop will check each radio button
/* i <= 3; may seem a little odd because there's
4 radio buttons, but the first rabio button is
treated as the 0th button,
the second radio as the 1rst,
and so on */
/* if one of the radio buttons is checked it gives
that value to the variable theValue */

for (i = 0; i <= 3; i++) {
if (document.myForm.answer[i].checked == true) {


if (theValue == correct) {
response ="Congrats! You got it!";
} else {
response ="Sorry," + " ";
response +=theValue;
response +=" " + "is not correct.";




What's 2+2?

<form name="myForm">
<table border="1">

<!-- by giving the radio buttons the same name,
only one can be checked at a time -->
<input type="radio" name="answer" value="1" />1
<input type="radio" name="answer" value="2" />2
<input type="radio" name="answer" value="3" />3
<input type="radio" name="answer" value="4" />4

<input type="button" onClick="check()" value="Submit" />

<!-- This is where the computer's output will be,
you can do the same with with a textarea
as well -->
<input type="text" name="txtResponse" />



Ironicly I had the same error last night while working on a quiz program that's purely JavaScript and HTML. I forget now how I fixed it.

Hope it helps, Thanks, Death

PS - I remember what it was I did now. I had 6 radio buttons per question, and each set of buttons had their own name. The problem was in this line:

Expand|Select|Wrap|Line Numbers
  1. for (i = 0; i <= 6; i++) {
  3. }
The problem as you might have guessed is in the "i <= 6;" section. This is telling the browser that there's 7 radio buttons, but I only had 6. I changed the line to "i <= 5;" and it worked like a charm.
Nov 26 '07 #2
Thanks for the reply.

What i want to do?
I have radio buttons corresponding to some id's retrieved from database.
Next each parent radio button has several child buttons(retrieved from database).
When i select a parent button only one child button has to be selected and when i move from one child to another child radio button belonging to the same parent the previous child radio has to be de-selected automatically and next clicked radio to be selected.
When i select a parent radio only one parent radio has to be selected and when i move to another parent radio the previous parent has to be deselected and new parent radio selected.

P.N: The no. of radio's in a list depends on the database.

The proble lies in this line
Expand|Select|Wrap|Line Numbers
  1. if (thisObj.checked && (!thisObj.form.elements[parentRadioButtonName].checked)) {
When i debugged with IE debugger it shows the below values for the above statement:

thisObj.checked = true
(!thisObj.form.elements[parentRadioButtonName].checked) = error

Hope i was able to explain properly.
Nov 27 '07 #3

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

Similar topics

by: Building Blocks | last post by:
Hi, All I need is a simle calculate form script which contains this: A script that can handle text input, radio buttons, checkboxes, and dropdowns. Each one of these variables will contain a...
by: Edward | last post by:
The below code builds 2 tables 4 rows by 4 cols. All cells have checkboxes. When checked, the checkboxes in the first column automatically check the remainder of the check boxes in the same row. ...
by: michael | last post by:
apologies in advance, as not only am i new to learning how to code javascript properly, i'm new to the groups posting thing... i am developing in firefox 1.0+, but will be working in an msie 6.0+...
by: Sean Shanny | last post by:
To all, The facts: PostgreSQL 7.4.0 running on BSD 5.1 on Dell 2650 with 4GB RAM, 5 SCSI drives in hardware RAID 0 configuration. Database size with indexes is currently 122GB. Schema for...
by: Ed Jay | last post by:
When I run the below js, I get the error: "document.form1.elements.checked) is null or not an object" <script type="text/javascript"> function get_menu_value(menu_name) { var mValue = 0; ...
by: judge82 | last post by:
I made sure I closed all the bracket, why do i still get the error. on line 360, 424, 425 and 607 Please help /* * ShopCartServletHW3.java *
by: break9 | last post by:
I have a form that I uses javascript and <tr> tags to display or hide form fields. The problem is that Firefox won't acknowledge or pass any variables from any fields that were hidden when the page...
by: premprakashbhati | last post by:
i want to have checkboxes in my gridview ...by checking it ,i can delete the row/rows.... so i have written code and got 2 Errors ...can anyone solve it... Error:1...'gridview.RetrieveItems()': not...
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...

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.