Jump to content

Clone field set


nottoolate

Recommended Posts

Hello,

 

I am creating a form and I have a field set for client information and the ability to add another field set for another client if needed.

As of now the additional field sets' field id adds by 1 which is good, but I would like for each of the fields in the field set to add by 1 as well.

 

Here is the code:

var _counter = 0;
function Add() {
_counter++;
var oClone = document.getElementById("client").cloneNode(true);
oClone.id += (_counter + "");
document.getElementById("placehere").appendChild(oClone);

 

Link to comment
https://forums.phpfreaks.com/topic/253311-clone-field-set/
Share on other sites

  • 2 weeks later...

any input?

 

Here is what I'm getting:

 

The original section

<fieldset id="child1">
<table id="1">
<tr>
<td>Child</td>
<td><select name="pm1" id="pm1"><option value="1">Yes</option><option value="2">No</option></td>
</tr>
<td>Account</td>
<td><input type="text" id="pa1" name="pa1" /></td>
</tr>
</table>
</fieldset>

 

The newly added section (Notice how the id is the same except for the fieldset)

<fieldset id="child2">
<table id="1">
<tr>
<td>Child</td>
<td><select name="pm1" id="pm1"><option value="1">Yes</option><option value="2">No</option></td>
<td>Account</td>
<td><input type="text" id="pa1" name="pa1" /></td>
</tr>
</table>
</fieldset>

 

What I want

<fieldset id="child2">
<table id="1">
<tr>
<td>Child</td>
<td><select name="pm2" id="pm2"><option value="1">Yes</option><option value="2">No</option></td>
<td>Account</td>
<td><input type="text" id="pa2" name="pa2" /></td>
</tr>
</table>
</fieldset>

 

Link to comment
https://forums.phpfreaks.com/topic/253311-clone-field-set/#findComment-1302656
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.