473,396 Members | 2,093 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,396 software developers and data experts.

Checkbox group disable

Hello JS Group

I have a few checkbox groups in my form . I would like to enable or disable them based on some values chosen in option boxes. I have the following code, the disableGroup function is a variation of enableGroup function from this example

in radio button :
Expand|Select|Wrap|Line Numbers
  1. onclick="javascript:disableSomething()"
and the disableSomething() and disableGroup are:

Expand|Select|Wrap|Line Numbers
  1. function disableSomthing() 
  2.         {
  3.         var name1 = 'checkboxgroup1';
  4.         var name2 = 'checkboxgroup2';
  5.         var formname = 'theFormName';
  6.  
  7.         disableGroup(name1,formname);
  8.         disableGroup(name2,formname);
  9.  
  10.         ..............     
  11.         }
  12.  
  13.          function disableGroup(name, form) {
  14.          var group = form.elements[name];
  15.          for(var i = 0, n = group.length; i < n; ++i) {
  16.          group[i].disabled = true;
  17.          }
  18.          }
But when I run the code I get error:

"elements is null or not an object".

I have tried to figure out what is wrong but failed.Could you please have a look at my code and advise ? I'd be grateful.

Regards
Vajra
Nov 23 '07 #1
3 2272
acoder
16,027 Expert Mod 8TB
You're just passing the form name to disableGroup whereas it expects a form object.

Try document.forms[form].elements...
Nov 23 '07 #2
You're just passing the form name to disableGroup whereas it expects a form object.

Try document.forms[form].elements...

Many thanks for the answer , the method you recommended works. I also tried doing it with getElementsById (to omit form name) but nothing happens:

Expand|Select|Wrap|Line Numbers
  1. var group = document.getElementById(name);

It would be great if you could tell me how to make the above work as well.

Many thanks and regards
Vajra
Nov 23 '07 #3
acoder
16,027 Expert Mod 8TB
getElementById only gets one element. Since checkboxes are a group of elements, you will need to use document.getElementsByName instead.
Nov 26 '07 #4

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

Similar topics

1
by: John Mullen | last post by:
I want to take the following HTLM and use javascript to turn on radio buttons if checkbox is checked, can I do this with javascript (maybe onClick or an array) or do i need a server side script ?...
6
by: ML.Steve | last post by:
Hi, There are lots of posts on this subject but after a couple of hours of going though them I still can't get a number of fields to be disabled when a checkbox is ticked. Basically I have a...
2
by: Kufre | last post by:
I need anyone that have done this before to help me. I'm creating a form in Access, in the form has two two checkbox, checkbox A is paid, checkbox B is partial_paid. I want the set the checkbox so...
5
by: fred | last post by:
hiya, I have got a checkbox in one of my cells in the ediit item template. Now i need to enable/disable a textbox in another boundcolumn. the problem i am facing is the checkchanged event is...
7
by: sheldonlg | last post by:
I have a checkbox that I set by php code to be either "checked" or "". I want to disable the ability of the user to check or uncheck it. I tried "readonly", but that didn't work. Any suggestions?
4
by: Matrixreloadedth | last post by:
How to change disable color of Checkbox??? I have a checkbox with forecolor in red but when i disable by set Enable properties to false forecolor is changed to gray color but i don't want it. how...
6
by: tshad | last post by:
I am trying to disable and enable a checkbox from javascript. The problem is that if the checkbox starts out as: <input id="Override" type="checkbox" name="Override"/> I can change it back...
2
by: Kevin | last post by:
I've been looking all over and I can't seem to find what ought to be simple. I need to disable a drop down when a checkbox is checked, and enable it when same checkbox is unchecked. I've...
4
by: Richard Walker | last post by:
Hi I'm trying to disable/enable a group of checkboxes using javascript, but can't work out how to refer to them. eg: <form name="selectform" action="data.php" method="post"> <input...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.