Solved

javascript + hide textbox on checbox click

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
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…

685 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