"Show Hide Text Fields"
Bootstrap 3.1.0 Snippet by escapedlion

<link href="//netdna.bootstrapcdn.com/bootstrap/3.1.0/css/bootstrap.min.css" rel="stylesheet" id="bootstrap-css"> <script src="//netdna.bootstrapcdn.com/bootstrap/3.1.0/js/bootstrap.min.js"></script> <script src="//code.jquery.com/jquery-1.11.1.min.js"></script> <!------ Include the above in your HEAD tag ----------> <div class="container"> <div class="row"> <div class="col-md-6"> <h1>Toggle fields based on form values</h1> <p>Change the age field and see what happens</p> <form method="POST"> <p>Name: <input type="text" name="player_name" /> </p> <p>Email: <input type="text" name="player_email" /> </p> <p>Age: <select id="age" name="age"> <option value="13">13</option> <option value="14">14</option> <option value="15">15</option> <option value="16">16</option> <option value="17">17</option> <option value="18">18</option> <option value="19">19</option> <option value="20">20</option> <option value="21">21</option> <option value="22">22</option> <option value="23">23</option> <option value="24">24</option> <option value="25">25</option> <option value="0">Other</option> </select> </p> <div id="parentPermission"> <p>Parent's Name: <input type="text" name="parent_name" /> </p> <p>Parent's Email: <input type="text" name="parent_email" /> </p> <p>You must have parental permission before you can play.</p> </div> <p align="center"> <input type="submit" value="Join!" /> </p> </div> </div> </div> </form>
//Purpose: toggle the visibility of fields depending on the value of another field $(document).ready(function () { toggleFields(); //call this first so we start out with the correct visibility depending on the selected form values //this will call our toggleFields function every time the selection value of our underAge field changes $("#age").change(function () { toggleFields(); }); }); //Function: this toggles the visibility of the child field depending on the selected value of the parent function toggleFields() { if ($("#age").val() == 0) $("#parentPermission").show(); else $("#parentPermission").hide(); }

Related: See More


Questions / Comments: