Click here to Skip to main content
15,919,500 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
There two checkbox...When checkbox1 is select, display what it is hidden...it is fine when checkbox2 is check is hidden or don't show anything.But when it is check checkbox1 , i made uncheck the display it is not hidden the block

<input type="checkbox" ID="chebox1"   runat="server" class="check"  onclick="select()"/&gt
<input type="checkbox" ID="chebox2"   runat="server" class="check"  onclick="unselect()"/&gt


<pre lang="xml"><script type="text/javascript">

   function select() {


        document.getElementById("div").style.display = "block";

   }

     function unselect(){


         document.getElementById("div").style.display = "none";
    }
    </script>



Posted
Comments
harish85 29-Jun-11 18:36pm    
What behavior did you saw while checkbox1 is checked and unchecked, what was expected? didnt understand clearly from ur post
Chamiss 29-Jun-11 18:51pm    
When I check checkbox if display my another stuff that i hidden , but if I uncheck the checkbox1 should be hidden my stuff but it is visible only if i uncheck the checkbox2 make invisible

This design is wrong. What if both are checked ? Have one checkbox and make your code check if it's checked and hide/unhide based on that. You can do select(this) to pass your checkbox in to the method and not need to look it up.
 
Share this answer
 
Comments
Chamiss 30-Jun-11 9:17am    
Yeah over design is wrong.. I know becasue when I paste, it goes like...I have right in my code.. yes, i did that but it is not work like I want.. I think I should be make a function for both to either one. I still stuck in this
avoid using select() as user function name , but still I didn't understand your problem well.

notes -
if you want to check the state of checkbox and then hide or display you can pass the checkbox id to function. (checked property)
 
Share this answer
 
Try using following code

function select()
{

  if (document.getElementById("checkbox1").checked)
    document.getElementById("div1").style.display = ''
  else
    document.getElementById("div1").style.display = 'none'
}


function unselect(){
{
   if (document.getElementById("checkbox2").checked)
   document.getElementById("div1").style.display = 'none'
 else
   document.getElementById("div1").style.display = ''
}
 
Share this answer
 
Comments
Chamiss 30-Jun-11 9:17am    
It is not working this... checkbox1 doesn't display anything

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900