I want to create a checkbox on a form that, when checked, will display a text field for someone to enter text into. If the box isn't checked, though, the text field should not be displayed.
How do I do this?
Oh also, it will probably use document.getElementByID(), because that is what we're learning about
<input type="checkbox" onclick="document.getElementById('show_me').style.display = this.checked ? '' : 'none';" />
<input id="show_me" type="text" style="display: none;" />
Last edited by bionoid; 12-12-2011 at 05:09 PM.
Reason: Added <form> tags even though they're uneless :P
Hrm.... How would I apply this to multiple text boxes + tags?
I thought I could put them all under an article with the ID show_me, but that didn't really work.
simplest with what you've got now would be just to duplicate the code, swapping "show_me" for some other id (and doing this in the onclick, too)
probably better would be storing the checkboxes in an array and looping through them, but I suspect that if you submitted that your teacher may get a little suspicious.
Wouldn't that mean multiple checkboxes?
And yeah, we haven't learned about arrays yet, so I don't think he's expecting that.
Oh it works with the id in the article, the style= attribute thing was messing it up apparently.
Now I just need to have it not show right at the start, rather than when I uncheck the box... hmm....
omg im stupid, fixed it now though
THANKS FOR THE HELP BIONOID!!!!
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)