I have a text input with a name first_name[120] (predefined key), and I would like to copy the value into another first_name[different predefined key] field with a click of a button.
There may be other first_name[different predefined key] fields in the form so I need the flexibility to make this work for the rest. Any suggestions?
EDIT:
Sorry, I think I need to give a little more information.
The form has a list of fields for gift recipient(s) information. There may be multiple gifts listed in the form, with each one having its own fieldset for entering the gift recipient's info. Basically, I am trying to make a "Copy info from above" feature for subsequent gift recipient fields in the form.
EDIT 2:
This is my solution and it works. Please suggest improvements if possible. It is actually bound to a dropdown with a list of all gifts. So the code knows which section to pull the info from and where to drop it based on the id of the dropdown (e.g. 123|130).
$('.copy_info').live('change', function(){
var ids = $(this).val().split('|');
var from = ids[0];
var to = ids[1];
$('#form_fields-' + from + " :input").each(function(){
var name = $(this).attr('name');
var new_name = name.replace(/[\d+]/,to);
$('#form_fields-' + to + ' input[name="' + new_name + '"]').val($(this).val());
});
});