I have an entire div I'd like to clone with jquery. I got the cloning part down, but when I selected the radio buttons I noticed it would only select one option out of all the clones which instantly told me they all still possessed the same names and IDs as the originals.
Now that this has my brain going, I'd like to change the names and ids of these elements by keeping the same name and just adding "02,03,04" to the end each time it's cloned otherwise once someone submits the form I'll have no clue as to which answers belong to which elements originally.
here's a fiddle of a simpler demo that represents the structure of what I'm trying to manipulate. https://jsfiddle.net/6djnv9u2/1/
and here's the coding I have so far.
$(document).ready(function(){
$("#dplct").click(function(){
$("#container01").clone("*").appendTo("#page01").after("#container01");
});
});
<form>
<div id="page01">
<div id="container01">
<label for="fname">First Name</label>
<input type="text" name="First name" id="fname">
<label for="lname">Last Name</label>
<input type="text" name="Last name" id="lname">
<label for="stf">Stuff</label>
<textarea name="stuff" id="stf"></textarea>
<label for="dplct">Duplicate</label>
<input type="button" name="Duplicate" id="dplct">
<input type="radio" name="1" value="1" id="q1a1">
<input type="radio" name="1" value="2" id="q1a2">
<input type="radio" name="1" value="3" id="q1a3">
<label for="nxt">Next</label>
<input type="button" name="Next" id="nxt">
</div><!--container-->
</div><!--page01-->
</form>
I looked through the rest of the site and came across other examples of changing names but none I could recognize as keeping the same name and adding to the end to make them unique, so if there's something here that shows it PLEASE let me know before tearing my head off about not trying hard enough, I honestly don't know where to go from here and can't think of anything deeper to add to this. Where do I go from here?