/    Sign up×
Community /Pin to ProfileBookmark

Hello,

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.

[CODE]var _counter = 0;
function Add() {
_counter++;
var oClone = document.getElementById(“client1”).cloneNode(true);
oClone.id += (_counter + “”);
document.getElementById(“placehere”).appendChild(oClone);[/CODE]

Here is what I’m getting:

The original section

[code=html]<fieldset id=”client1″>
<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>[/code]

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

[code=html]<fieldset id=”client2″>
<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>[/code]

What I want

[code=html]
<fieldset id=”client2″>
<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>[/code]

to post a comment
JavaScript

3 Comments(s)

Copy linkTweet thisAlerts:
Jan 05.2012 — i dunno if its me that's a stupid simpleton. The thing you're trying to achieve would it be possible to achieve by just appending text like this:
[code=php]document.getElementById().innerHTML+='<fieldset id="client'+indexVariable+'">'; // and more ofc[/code]

but storing the template for appending in a javascript string variable.
Copy linkTweet thisAlerts:
@newjackauthorJan 05.2012 — No, because I'm not trying to increment the fieldset id. (this already works correctly)

I'm trying to increment the id for each of the tags (input, select, etc.) within the fieldset.
Copy linkTweet thisAlerts:
@newjackauthorJan 05.2012 — I've solved my problem. Everything works correctly now.
×

Success!

Help @newjack spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.19,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...