HTML + jQuery
We will have our form inside a container with ID 'myform'. Notice the onclick attribute on radio buttons. You will see that I have placed some javascript there. They will take care the toggling (show/hide) of the email address input field.
- <div id="myform">
- <h3>Do you want to subscribe to our newsletter?</h3>
- <form>
- <input onclick="javascript: $('#email').show('slow');" type="radio" name="subscribe" value="1" />
- <label>Yes, I want to subscribe</label>
- <br />
- <input onclick="javascript: $('#email').hide('slow');" type="radio" name="subscribe" value="0" />
- <label>No, thanks</label>
- <br />
- <div id="email">
- <label>Email Address: </label>
- <input name="email" type="text" />
- </div>
- </form>
- </div>
Must remind you to link to jQuery library in your HEAD tag.
CSS
We start by defining some properties for our container.
- #myform {
- padding: 10px;
- background-color: #eee;
- width: 400px;
- border: 1px solid #ccc;
- }
- #myform h3 {
- font-weight: normal;
- }
Time for some labels and inputs (form elements).
- #myform label {
- font-size: 18px;
- }
- #myform input[type=text] {
- font-size: 20px;
- width: 200px;
- }
Email address field should be hidden when your document loads in a browser
- #email {
- margin: 20px 0px 0px 0px;
- display: none;
- }
Okay, everything done now. Open your webpage in a browser and see yourself!













