Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

add onclick event to disable button when checkboxes are not checked

Posted on 2008-06-26
2
Medium Priority
?
992 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 2000 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

OverviewThis article demonstrates a simple search form using AJAX. The purpose of the article is to demonstrate how to use the same code to render a page and javascript (JQuery) and AJAX to make subsequent calls to refine the results. The princip…
Introduction A frequently asked question goes something like this:  "I am running a long process in the background and I want to alert my client when the process finishes.  How can I send a message to the browser?"  Unfortunately, the short answer…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Suggested Courses

971 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