[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

onClick checkbox to show and hide a div area

Posted on 2005-04-20
5
Medium Priority
?
1,706 Views
Last Modified: 2008-04-08
using the function below and an  onClick="comm_direct_change(); on a check box, I can show a hidden area.

function comm_direct_change(){
      if (document.edit_campaign.comm_direct.checked){
            document.getElementById('direct').style.display='block';
      }
}

<div style="display: none;" id="direct" class="result">
content
</div>

What the check box is then unchecked I want to hide the div and then show again if checked.

Any idea how I would do this?

Regards,

dt

0
Comment
Question by:mrduckers
  • 2
  • 2
5 Comments
 
LVL 32

Accepted Solution

by:
Batalf earned 2000 total points
ID: 13822913
Something like this:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<script>
function comm_direct_change(checked){
     document.getElementById('direct').style.display = checked?"block":"none";
}
</script>
<input type="checkbox" onclick="comm_direct_change(this.checked)">Show
<div style="display: none;" id="direct" class="result">
content
</div>
</BODY>
</HTML>


the status of the checkbox is sent to the function, and the display property is set to block or none based on this status.
0
 
LVL 33

Expert Comment

by:sajuks
ID: 13822919
    if (document.edit_campaign.comm_direct.checked){
          document.getElementById('direct').style.display='block';
     }
     else
     {
            document.getElementById('direct').style.display='none';
     }
0
 
LVL 32

Expert Comment

by:Batalf
ID: 13822967
This is about the same as my first solution, but it supports several divs from the same function. This is done by passing the id of the div to the function

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<script>
function comm_direct_change(checked,elementID){
     document.getElementById(elementID).style.display = checked?"block":"none";
}
</script>
</head>
<body>

<input type="checkbox" onclick="comm_direct_change(this.checked,'direct')">Show<br>
<div style="display: none;" id="direct" class="result">
content
</div>
<input type="checkbox" onclick="comm_direct_change(this.checked,'direct2')">Show<br>
<div style="display: none;" id="direct2" class="result">
More content
</div>
<input type="checkbox" onclick="comm_direct_change(this.checked,'direct3')">Show
<div style="display: none;" id="direct3" class="result">
Even more content
</div>
</BODY>
</HTML>
0
 

Author Comment

by:mrduckers
ID: 13823006
Accepted first correct answer, thanks for spedy response.
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
A while back, I ran into a situation where I was trying to use the calculated columns feature in SharePoint 2013 to do some simple math using values in two lists. Between certain data types not being accessible, and also with trying to make a one to…
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

872 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