Solved

add onclick event to disable button when checkboxes are not checked

Posted on 2008-06-26
2
981 Views
Last Modified: 2008-06-27
Hi all,

I have a table that contains a list of checkboxes.

i need to create a function in JAVASCRIPT that will do the following:
 say i have 10 checkboxes .. one on each table row.
if a  user unchecks all of the check boxes i need to set disable=true to  button1
if all the check boxes are not unchecked then i need to set disable = false to button1

thanks
0
Comment
Question by:joan2006
2 Comments
 
LVL 82

Accepted Solution

by:
hielo earned 500 total points
ID: 21879742
Save this as test.html and try it.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
 "http://www.w3.org/TR/html4/loose.dtd">
 
<html>
<head>
<title></title>
<script type="text/javascript">
function process( o )
{
	var sib = document.getElementsByTagName(o.tagName);
	var checked=0;
	for( var i=0; i < sib.length; ++i)
	{
		if( sib[i].name==o.name && sib[i].checked==true )
		{
			++checked;
		}
	}
 
	if( checked==(sib.length-1) )
	{
		document.getElementById("theButtonID").disabled=false;
	}
	else
	{
		document.getElementById("theButtonID").disabled=true;
	}
return true;
}
</script>
</head>
<body>
<table summary="">
<tr><td><input type="checkbox" name="theCheckbox" onclick="process(this)" /></td></tr>
<tr><td><input type="checkbox" name="theCheckbox" onclick="process(this)" /></td></tr>
<tr><td><input type="checkbox" name="theCheckbox" onclick="process(this)" /></td></tr>
<tr><td><input type="checkbox" name="theCheckbox" onclick="process(this)" /></td></tr>
<tr><td><input type="checkbox" name="theCheckbox" onclick="process(this)" /></td></tr>
<tr><td><input type="checkbox" name="theCheckbox" onclick="process(this)" /></td></tr>
<tr><td><input type="checkbox" name="theCheckbox" onclick="process(this)" /></td></tr>
<tr><td><input type="checkbox" name="theCheckbox" onclick="process(this)" /></td></tr>
<tr><td><input type="checkbox" name="theCheckbox" onclick="process(this)" /></td></tr>
<tr><td><input type="checkbox" name="theCheckbox" onclick="process(this)" /></td></tr>
<tr><td><input type="button" name="theButton" id="theButtonID" value="Test" disabled="disabled" /></td></tr>
</table>
</body>
</html>

Open in new window

0
 
LVL 8

Expert Comment

by:newbie27
ID: 21885744
Hello Hielo,
You probably trying to ignore me and my posts otherwise all my problems would have resolved by now, Please Hielo, if anything said or done wrong please forgive and please please help me ! i know you been busy helping others as well but I would be very grateful to you HIELO for your help on the List Manager project I am working on, I need your help and advice
Please help HIELO.
Thanks
S
0

Featured Post

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
VS 2012 Ajax Mess 4 46
AJAX Call with two returns 19 78
XSS cleaning when using ajax & json encode 5 50
fade new row in after record insert with jQuery/ajax/php 18 90
Introduction Got endorsements from your clients?  Great!  There is almost nothing better than word-of-mouth advertising.  But how can you do that on the internet?  Sure you can make a page for endorsement quotations and list them all, but who is …
The Confluence of Individual Knowledge and the Collective Intelligence At this writing (summer 2013) the term API (http://dictionary.reference.com/browse/API?s=t) has made its way into the popular lexicon of the English language.  A few years ago, …
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question