Last active
September 22, 2016 10:15
-
-
Save Takaya213/9b96a0b6308e1e6663c980cc87a49e3c to your computer and use it in GitHub Desktop.
Clone a section of form code and increment the name/is of the inputs.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div class="input_fields_wrap"> | |
<div> | |
<input type="text" name="fields[contact][new1][fields][contactName]" /><br /> | |
<input type="text" name="fields[contact][new1][fields][contactSurname]" /><br /> | |
<input type="text" name="fields[contact][new1][fields][contactEmail]" /> | |
</div> | |
<button class="add_field_button">Add More Fields</button> | |
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
jQuery(document).ready(function($) { | |
var wrapper = $(".input_fields_wrap div"); //Fields wrapper | |
var add_button = $(".add_field_button"); //Add button Class/ID | |
var x = 1; //initlal text box count | |
$(add_button).click(function(e){ //on add input button click | |
e.preventDefault(); | |
x++; //text box increment | |
var name = $(wrapper).children('input').attr('name').replace('[new1]', '[new'+x+']'); | |
$(wrapper).last().clone() | |
.insertBefore(add_button).children('input').attr('name', name); //add input box | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment