Solved

javascript + hide textbox on checbox click

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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Suggested Solutions

Today I would like to talk about localizing (Internationalization) JavaScript applications. Introduction When creating an application that is going to be used by many people around the globe, it is important to remember that not everyone speak…
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…
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…

809 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