Solved

javascript + hide textbox on checbox click

Posted on 2006-07-23
2
315 Views
Last Modified: 2010-05-18
i have 4 checkboxes and when one is clicked i want to either hide or display are textbox inside a div statment, so if the checkbox is checked it displays the <div> if not is hides, there is 4 <div> statements as well corrosponding to each checkbox.

Thanks

0
Comment
Question by:dkilby
  • 2
2 Comments
 
LVL 4

Accepted Solution

by:
jfredrickson earned 500 total points
ID: 17163976
Include this function on your page:

function toggle(target) {
            obj=(document.all) ? document.all[target] : document.getElementById(target);
            obj.style.display = (obj.style.display == 'block') ? 'none' : 'block';
      }

Then use the following code for each checkbox (just change the stuff all in caps):

<input type="checkbox" name="NAME" onclick="toggle('DIV_ID')" />

And of course set display:none; for each of the elements so that they start of hidden. Then when the user clicks on the checkbox to check it, the element will appear.
0
 
LVL 4

Expert Comment

by:jfredrickson
ID: 17163978
Of course you have to wrap that function in script tags and it should go in your head tag:

<script type="text/javascript">
function toggle(target) {
          obj=(document.all) ? document.all[target] : document.getElementById(target);
          obj.style.display = (obj.style.display == 'block') ? 'none' : 'block';
     }
</script>
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

In this article, we'll look how to sort an Array in JavaScript, including the more advanced techniques of sorting a collection of records either ascending or descending on two or more fields. Basic Sorting of Arrays First, let's look at the …
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 …
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…

707 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now