Though you have proposed a javascript
JavaScript solution for your problem (Displayingdisplaying a textbox
when a checkbox
is checked
), this problem could be solved just by css. With this approach, your form works for users who have disabled javascript
JavaScript.
Assuming that you have the following html
HTML:
<label for="show_textbox">Show Textbox</label>
<input id="show_textbox" type="checkbox" />
<input type="text" />
You can use the following css
CSS to achieve the desired functionality:
#show_textbox:not(:checked) + input[type=text] {display:none;}
For other scenarios, you may think of appropriate css selectors
CSS selectors.