?
Solved

If all checkboxes unchecked - toggle button visibility

Posted on 2003-03-24
8
Medium Priority
?
397 Views
Last Modified: 2012-05-04
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" ?
0
Comment
Question by:tbaseflug
  • 5
  • 3
8 Comments
 
LVL 46

Expert Comment

by:fritz_the_blank
ID: 8197458
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
0
 
LVL 46

Expert Comment

by:fritz_the_blank
ID: 8197468
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
0
 

Author Comment

by:tbaseflug
ID: 8197595
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?
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 

Author Comment

by:tbaseflug
ID: 8197622
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?
0
 
LVL 46

Accepted Solution

by:
fritz_the_blank earned 200 total points
ID: 8197746
Here you go:

<HTML>
<HEAD>
<META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0">
<TITLE></TITLE>
<SCRIPT LANGUAGE=javascript>
<!--
function setVisible(){

     var objForm = document.forms[0];
     bolVisible = false;
     if(!objForm.checkbox1.length && objForm.checkbox1.checked){
          bolVisible=true;
     }else{
          for(i=0;i<objForm.checkbox1.length;i++){
              if(objForm.checkbox1[i].checked){
                   bolVisible=true;
                   break;
              }
          }
     }
      if(bolVisible){
           objForm.button1.style.visibility = "visible";
      }else{
           objForm.button1.style.visibility = "hidden";
     }
}

//-->
</SCRIPT>

</HEAD>
<BODY>
<FORM action="" method=POST id=form1 name=form1>
<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
0
 
LVL 46

Expert Comment

by:fritz_the_blank
ID: 8197751
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
0
 

Author Comment

by:tbaseflug
ID: 8198335
Awesome - works great!
0
 
LVL 46

Expert Comment

by:fritz_the_blank
ID: 8198367
Glad to have helped,

Fritz the Blank
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

I've been trying to accomplish this for a while and it just struck me yesterday how to accomplish this task. I have done searches all over the internet looking for ways to email pages from my applications and finally I have done it!!! Every single s…
Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

578 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