?
Solved

javascript + hide textbox on checbox click

Posted on 2006-07-23
2
Medium Priority
?
322 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
2 Comments
 
LVL 4

Accepted Solution

by:
jfredrickson earned 2000 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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

In my daily work (mainly using ASP.net), I need to write a lot of JavaScript code. One of the most repetitive tasks I do are the jQuery Ajax calls. You know: (CODE) I don't know if for you it's the same, but for me is soooo tedious to write the …
I've been trying to accomplish this for a while and it just struck me yesterday how to accomplish this task. I have done searches all over the internet looking for ways to email pages from my applications and finally I have done it!!! Every single s…
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

770 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