"Dynamic Form Fields - Add & Remove BS3"
Bootstrap 3.3.0 Snippet by kbhokray

<link href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.0/css/bootstrap.min.css" rel="stylesheet" id="bootstrap-css"> <script src="//maxcdn.bootstrapcdn.com/bootstrap/3.3.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-5 form-group controls"> <label class="mr-sm-2" for="signatory">Signatories</label> <div class="input-group entry"> <select default="Default" name="signatories" class="form-control mb-2 mr-sm-2 mb-sm-0" id="signatories"> <option value="id1">Person1</option> <option value="id2">Person2</option> <option value="id3">Person3</option> <option value="id4">Person4</option> </select> <span class="input-group-btn"> <button class="btn btn-success btn-add" type="button"> <span class="glyphicon glyphicon-plus"></span> </button> </span> </div> </div> </div> </div>
.entry:not(:first-of-type) { margin-top: 10px; }
$(function() { $(document).on('click', '.btn-add', function(e) { e.preventDefault(); var controlForm = $('.controls'), currentEntry = $(this).parents('.entry:first'), newEntry = $(currentEntry.clone()).appendTo(controlForm); newEntry.find('input').val(''); controlForm.find('.entry:not(:last) .btn-add') .removeClass('btn-add').addClass('btn-remove') .removeClass('btn-success').addClass('btn-danger') .html('<span class="glyphicon glyphicon-minus"></span>'); }).on('click', '.btn-remove', function(e) { $(this).parents('.entry:first').remove(); e.preventDefault(); return false; }); });

Related: See More


Questions / Comments: