Link to home
Start Free TrialLog in
Avatar of tbaseflug
tbaseflugFlag for United States of America

asked on

If all checkboxes unchecked - toggle button visibility

Currently, I have a set of dynamically generated checkboxes (all with the same name = "checlbox") - presently, when I click on any one of the checkboxes, it switches the visibility of a button to "visible" -

what I would like to do, is if all the checkboxes are unchecked then the button's visibility switches back to "hidden" ?
Avatar of fritz_the_blank
fritz_the_blank
Flag of United States of America image

Here you go:

<HTML>
<HEAD>
<META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0">
<TITLE></TITLE>
<SCRIPT LANGUAGE=javascript>
<!--
function setVisible(){
bolVisible = false;
for(i=0;i<document.forms[0].checkbox1.length;i++)
     if(document.forms[0].checkbox1[i].checked){
          bolVisible=true;
          break;
     }
     if(bolVisible){
          document.forms[0].button1.style.visibility = "visible";
     }else{
          document.forms[0].button1.style.visibility = "hidden";
     }
}

//-->
</SCRIPT>

</HEAD>
<BODY>
<FORM action="" method=POST id=form1 name=form1>
<INPUT type="checkbox" name=checkbox1 onClick="setVisible()">
<INPUT type="checkbox" name=checkbox1 onClick="setVisible()">
<INPUT type="checkbox" name=checkbox1 onClick="setVisible()">
<INPUT type="checkbox" name=checkbox1 onClick="setVisible()">
<INPUT type="checkbox" name=checkbox1 onClick="setVisible()">
<INPUT type="button" value="Button" id=button1 name=button1 style="visibility=hidden">
</FORM>
</BODY>
</HTML>


Fritz the Blank
If you want me to clean this up and make it more abstracted, let me know. I just posted this quickly to give you a sense of how to approach this problem

Fritz the Blank
Avatar of tbaseflug

ASKER

Fritz -

This works great if I have more than 1 checkbox - the amount of checkboxes displayed is dynamic from a asp loop - so it could be 1 or more at any given time?
Fritz -

This works great if I have more than 1 checkbox - the amount of checkboxes displayed is dynamic from a asp loop - so it could be 1 or more at any given time?
ASKER CERTIFIED SOLUTION
Avatar of fritz_the_blank
fritz_the_blank
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
The above checks to see if there is an array of checkboxes. If not, it looks for the single control, otherwise it processes the array.

Fritz the Blank
Awesome - works great!
Glad to have helped,

Fritz the Blank