"Dynamic Form Fields - Add & Remove Multiple fields"
Bootstrap 3.3.0 Snippet by shafi-+8801915884826

<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="panel panel-default"> <div class="panel-heading">Dynamic Form Fields - Add & Remove Multiple fields</div> <div class="panel-heading">Education Experience</div> <div class="panel-body"> <div id="education_fields"> </div> <div class="col-sm-3 nopadding"> <div class="form-group"> <input type="text" class="form-control" id="Schoolname" name="Schoolname[]" value="" placeholder="School name"> </div> </div> <div class="col-sm-3 nopadding"> <div class="form-group"> <input type="text" class="form-control" id="Major" name="Major[]" value="" placeholder="Major"> </div> </div> <div class="col-sm-3 nopadding"> <div class="form-group"> <input type="text" class="form-control" id="Degree" name="Degree[]" value="" placeholder="Degree"> </div> </div> <div class="col-sm-3 nopadding"> <div class="form-group"> <div class="input-group"> <select class="form-control" id="educationDate" name="educationDate[]"> <option value="">Date</option> <option value="2015">2015</option> <option value="2016">2016</option> <option value="2017">2017</option> <option value="2018">2018</option> </select> <div class="input-group-btn"> <button class="btn btn-success" type="button" onclick="education_fields();"> <span class="glyphicon glyphicon-plus" aria-hidden="true"></span> </button> </div> </div> </div> </div> <div class="clear"></div> </div> <div class="panel-footer"><small>Press <span class="glyphicon glyphicon-plus gs"></span> to add another form field :)</small>, <small>Press <span class="glyphicon glyphicon-minus gs"></span> to remove form field :)</small></div> <div class="panel-footer"><small><em><a href="http://shafi.info/">More Info - Developer Shafi (Bangladesh)</a></em></em></small></div> </div>
var room = 1; function education_fields() { room++; var objTo = document.getElementById('education_fields') var divtest = document.createElement("div"); divtest.setAttribute("class", "form-group removeclass"+room); var rdiv = 'removeclass'+room; divtest.innerHTML = '<div class="col-sm-3 nopadding"><div class="form-group"> <input type="text" class="form-control" id="Schoolname" name="Schoolname[]" value="" placeholder="School name"></div></div><div class="col-sm-3 nopadding"><div class="form-group"> <input type="text" class="form-control" id="Major" name="Major[]" value="" placeholder="Major"></div></div><div class="col-sm-3 nopadding"><div class="form-group"> <input type="text" class="form-control" id="Degree" name="Degree[]" value="" placeholder="Degree"></div></div><div class="col-sm-3 nopadding"><div class="form-group"><div class="input-group"> <select class="form-control" id="educationDate" name="educationDate[]"><option value="">Date</option><option value="2015">2015</option><option value="2016">2016</option><option value="2017">2017</option><option value="2018">2018</option> </select><div class="input-group-btn"> <button class="btn btn-danger" type="button" onclick="remove_education_fields('+ room +');"> <span class="glyphicon glyphicon-minus" aria-hidden="true"></span> </button></div></div></div></div><div class="clear"></div>'; objTo.appendChild(divtest) } function remove_education_fields(rid) { $('.removeclass'+rid).remove(); }

Related: See More


Questions / Comments:

Hi, how can we retrieve the collective data, say 4-5 rows in form of array??

dhruvsinghal007 () - 6 months ago - Reply 0


Thanks for snippets!

Can I have 2 questions more, please?

1. How to select values from pop-up list from MySQL DB instead to choose it from simple sequence (I mean Data field)?
2. How to get chosen values in php script (I think in $_POST array) for future processing?

Thank you in advance.

Vasyl Semeniuk () - 1 year ago - Reply 0


It adds new field in the middle, is there way to add new fields at either top or bottom?

Sandip Kc () - 1 year ago - Reply 0