473,395 Members | 1,535 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,395 software developers and data experts.

Disable some checkboxes

I create checkboxes using datas from a database (with PHP).
I store all values in an array, as I must pass this value like a Form value.

Now, in some cases, when a checkbox is selected, I must disactivate other
checkboxes.

How can I do this ?

here is the code:

print("<TR><TD valign=\"top\"><input type=\"checkbox\" name=\"details[]\"
value=\"".$row_Recordset->ID."\"></TD><TD
valign=\"top\">".$row_Recordset->Description);

here is the output: [] is for checkbox
[] Blue
[]
[]
[]
[]

Jul 23 '05 #1
5 5948


Bob Bedford wrote:
I create checkboxes using datas from a database (with PHP).
I store all values in an array, as I must pass this value like a Form value.

Now, in some cases, when a checkbox is selected, I must disactivate other
checkboxes.

How can I do this ?

here is the code:

print("<TR><TD valign=\"top\"><input type=\"checkbox\" name=\"details[]\"
value=\"".$row_Recordset->ID."\"></TD><TD
valign=\"top\">".$row_Recordset->Description);


Here is an example:

<html lang="en">
<head>
<title>checkbox disabling</title>
<script type="text/javascript">
function disableHandler (form, inputName) {
var inputs = form.elements[inputName];
for (var i = 0; i < inputs.length; i++) {
var input = inputs[i];
input.onclick = function (evt) {
if (this.checked) {
disableInputs(this, inputs);
}
else {
enableInputs(this, inputs);
}
return true;
};
}
}

function disableInputs (input, inputs) {
for (var i = 0; i < inputs.length; i++) {
var currentInput = inputs[i];
if (currentInput != input) {
currentInput.disabled = true;
}
}
}

function enableInputs (input, inputs) {
for (var i = 0; i < inputs.length; i++) {
var currentInput = inputs[i];
if (currentInput != input) {
currentInput.disabled = false;
}
}
}
</script>
</head>
<body>
<form name="aForm" action="">
<p>
<label>
Blue
<input type="checkbox" name="details[]" value="blue">
</label>
<label>
Green
<input type="checkbox" name="details[]" value="green">
</label>
<label>
Red
<input type="checkbox" name="details[]" value="red">
</label>
</p>
</form>
<script type="text/javascript">
disableHandler(document.forms.aForm, 'details[]');
</script>
</body>
</html>

Disabling form controls works in browsers like Netscape 6/7, IE4+, Opera
7 but not old ones like Netscape 4.

--

Martin Honnen
http://JavaScript.FAQTs.com/

Jul 23 '05 #2
Thanks for your code, Martin, but all checkboxes belong to the same array
(details[]) but this is not for grouping: the groups are different:

//1st group (colors)
[] Blue
[] Green
[] Red
[] Purple
//2nd group (size)
[] Big
[] Small
//3rd group (weight)
[] Heavy
[] Light

So clicking on any color item, it should disable all other colors items, but
not size and weight items
Also, one more difficulty, any item may be in different groups, so clicking
on any will disable all of his group.

So forget the previous example and take this better one: (all items must
have the name="details[]").
[] item1 (belong to group 1,2,4)
[] item2 (belong to group 1,2,4)
[] item3 (belong to group 1,2,4)
[] item4 (belong to group 1,3)
[] item5 (belong to group 3)
[] item6 (belong to group 4)

So:
clicking on item1, disable items 2,3,4,6
clicking on item2, disable items 1,3,4,5
clicking on item3, disable items 1,2,4,5
clicking on item4, disable items 1,2,3,5
clicking on item5, disable items 4 only
clicking on item6, disable items 1,2,3

I know it's quite complex !!!! how to do so ????

BoB

Jul 23 '05 #3


Bob Bedford wrote:

So forget the previous example and take this better one: (all items must
have the name="details[]").
[] item1 (belong to group 1,2,4)
[] item2 (belong to group 1,2,4)
[] item3 (belong to group 1,2,4)
[] item4 (belong to group 1,3)
[] item5 (belong to group 3)
[] item6 (belong to group 4)

So:
clicking on item1, disable items 2,3,4,6
clicking on item2, disable items 1,3,4,5
clicking on item3, disable items 1,2,4,5
clicking on item4, disable items 1,2,3,5
clicking on item5, disable items 4 only
clicking on item6, disable items 1,2,3

I know it's quite complex !!!! how to do so ????


Well there is the onclick handler to attach code to be called when the
input is clicked, the checked property to find out whether the checkbox
is checked and the disabled property to disable a property so you need
<input type="checkbox"
name="details[]"
onclick="if (this.checked) {
//disable needed inputs
this.form.elements[this.name][1].disabled = true;
}
else {
//enabled needed inputs e.g.
this.form.elements[this.name][1].disabled = false;
}
return true;">

It is up to you now to write down the code for the different checkboxes.

--

Martin Honnen
http://JavaScript.FAQTs.com/

Jul 23 '05 #4

"Martin Honnen" <ma*******@yahoo.de> a écrit dans le message de
news:40********@olaf.komtel.net...


Bob Bedford wrote:

So forget the previous example and take this better one: (all items must
have the name="details[]").
[] item1 (belong to group 1,2,4)
[] item2 (belong to group 1,2,4)
[] item3 (belong to group 1,2,4)
[] item4 (belong to group 1,3)
[] item5 (belong to group 3)
[] item6 (belong to group 4)

So:
clicking on item1, disable items 2,3,4,6
clicking on item2, disable items 1,3,4,5
clicking on item3, disable items 1,2,4,5
clicking on item4, disable items 1,2,3,5
clicking on item5, disable items 4 only
clicking on item6, disable items 1,2,3

I know it's quite complex !!!! how to do so ????


Well there is the onclick handler to attach code to be called when the
input is clicked, the checked property to find out whether the checkbox
is checked and the disabled property to disable a property so you need
<input type="checkbox"
name="details[]"
onclick="if (this.checked) {
//disable needed inputs
this.form.elements[this.name][1].disabled = true;
}
else {
//enabled needed inputs e.g.
this.form.elements[this.name][1].disabled = false;
}
return true;">

It is up to you now to write down the code for the different checkboxes.


How can I add an array to any details item and then go trough any item when
a box is checked ?

article[0] = item1 (value=123, exclude=(233,432,456))
article[1] = item2 (value=233, exclude=(432,456))
article[2] = item3 (value=455, exclude=(457,477,874))
....
so clicking on any item, it should look at his exclude list, and then go
trough all article's item and retrieve the one wich value = any of the
existing exclude number and disable it! also the ability to enable it again
if the article is unchecked.

How to do so in Javascript ?

Jul 23 '05 #5


Bob Bedford wrote:

How can I add an array to any details item and then go trough any item when
a box is checked ? How to do so in Javascript ?


The JavaScript docs are at
http://devedge.netscape.com/library/...1.5/reference/
the Array reference at
http://devedge.netscape.com/library/...y.html#1193137
there is also a guide at
http://devedge.netscape.com/library/...ipt/1.5/guide/
treating arrays here
http://devedge.netscape.com/library/...j.html#1008453
Now try to write some code yourself
--

Martin Honnen
http://JavaScript.FAQTs.com/

Jul 23 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: HolaGoogle | last post by:
Hi all, Can you please tell me what's wrong with my code??? i do have this database in wich i have to field.One is a "yes/no" field and another one is "number" field. To display the yes/no field...
2
by: HolaGoogle | last post by:
Can you please tell me the right way to do this?? it's realy important! thanks in advance... Hi all, Can you please tell me what's wrong with my code??? i do have this database in wich i have...
1
by: hortoristic | last post by:
We are using JavaScript to Enable/Disable certain fields on web pages based on business rules. A simple example is if when using an option type tag, and the two options are Yes and No. If YES...
9
by: Marc | last post by:
Okay, here's the problem - I have 3 radio buttons, and 11 check boxes (which are disabled by default). I have the javascript below which when the last radio button is clicked, enables the...
1
by: mkrei | last post by:
I have datagrid that I format at runtime with tablestyles and adding columns. I have a DataGridBoolColumn that I have subclassed, but can't get the right result. I want to disable a cell based on...
1
by: shobana | last post by:
Hi I have a bunch of checkboxes. While in fetch method iam checking it and disabling the checkbox which has data in backend. Rest are enabled. User can check the rest and update it. While in form...
5
by: masterej | last post by:
Developers, Is there any way to disable all checkboxes on a form? I have a form with 160 checkboxes and I want to be able to disable all of them. Is there a way I can do something like this: ...
1
by: MattB | last post by:
asp.net 1.1, vb.net I have a CheckBoxList that I need to conditionally disable one or more individual checkboxes from at runtime. I was hoping I could so something like:...
6
by: feninazman | last post by:
hi ;) i'm doing my intern now.this is my 1st time using ASP.NET web matrix with VB.NET language... i need help in disabling my checkboxes. i have 4 checkboxes, let say "air" "water" "ice" "snow"...
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:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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
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.