?
Solved

If all checkboxes unchecked - toggle button visibility

Posted on 2003-03-24
8
Medium Priority
?
395 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

 

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

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

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

Having worked on larger scale sites, we found out that you are bound to look at more scalable solutions to integrating widgets, code snippets or complete applications and mesh them into functional sites, in any given composition. To share some of…
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
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

770 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