Solved

javascript + hide textbox on checbox click

Posted on 2006-07-23
2
316 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

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…
This article discusses how to create an extensible mechanism for linked drop downs.
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…

867 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

16 Experts available now in Live!

Get 1:1 Help Now