SavantCode SavantCode - 1 year ago 85
jQuery Question

accordian, copy email addrress to each textfield

I have an accordian. And an email textfield. I want to copy the email address to each new textfield. But Now it only copies to the first textfield. And if I make a third textfield. It doesnt copy the email address from the first created textfield.

I have this:

// Add extra contact clicked?
$('#add-contact p a').click(function (e) {

// Make a copy of the first input fields
html = $('#new-contact').children().clone();

// Get number of tabs in the accordion
var index = $('#accordion h3').length;

// Remove the values
html.find('input[type=checkbox]').attr('checked', false);

// New 'id', 'for' and 'name' attribute names
html.find('input[type=checkbox]').each(function () {

me = $(this);
attr = me.attr('id');
number = attr.split('_')[2];
newNumber = parseInt(index) + 1;
newAttr = attr.replace(number, newNumber);
me.attr('id', newAttr).attr('name', newAttr).next().attr('for', newAttr);


// Insert it at the end


$("#add-contact p a").each(function () {


// Set last tab to active
$("#accordion").accordion({active: index});

// Cancel the click
return false;

and here I copy the email address:

$("#add-contact p a").each(function () {


But his copies only once. So from textfield 1 to textfield2. But then if I make a third textfied. It doesnt copy from textfield 1 to textfield3.

Thank you

I have this:

<div class="contact-label span2">
<label for="contactpersonen-email">Email adres</label>
<div class="contact-input-field">
<input type="text" class="input-text span2 required contactpersonen_email1" id="contactpersonen_email1" name="contactpersonen_email1"></input>

Answer Source

In fact, $("#contactpersonen_email1") will select the first item with this ID,

It should work right using classes instead of ids.

Like this :


Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download