"this" is a text field, "new_id" is an integer.
When I apply the following snippet:
$(this).attr('id', this.id + '_' + new_id);
$(this).attr('name', this.name + '_' + new_id);
$(this).attr('value', 'test');
the id changes, the name changes too, but not the value. If I change the last line to this (and therefore use a string literal)
$('#mytextfield_3').attr('value', 'test');
it works.
Any ideas?
-- EDIT -- Thanks to Steerpike for the quick plugin test - i believe it should work, but i can't find the error.
Here's some more code:
I create the clone using
clone = $(this).find('.clone_fields_container:first').clone();
"clone" now contains a div which has embedded input fields.
After generating a new id:
/** Iterate over input and select fields in container */
clone.children('input,select,textarea').each(function() {
$(this).attr('id', this.id + '_' + new_id);
$(this).attr('name', this.name + '_' + new_id);
$(this).val('test');
console.log(this);
});
The text fields do not have any values.