id of new object dynamically created in a nested form

In my nested form I have a link to open a popup with selections. When a selection is made, the popup closes and the selection is added to a text box.

Because I have objects that can be dynamically created in the form I can't just use the id of the object to assign the selection to the input text box.

I have this in my view

  <td><%= f.text_field :couchetype, :readonly=>true%></td>    <td><%= link_to( image_tag('more.png', :border=>0, :id=>"sample_sample"), {:controller=>"thesaurus", :action=>"list"}, { :popup=>['thesaurus', 'height=800,width=400,location=no,scrollbars=yes']}) %>    </td> </tr>

and then this in the popup

function copyData(id,value){     var el = window.opener.document.getElementById(id);     if (!el.value)        el.value = value;     else        el.value = el.value + "; " + value;     this.close(); }

I want to send the id of the new object to the popup so that I can refind the text box to assign the selections. How can I do that?