RJS: pass javascript variables in ruby calls


I have this link_to_function which takes an RJS block as follows:

page.insert_html :bottom, :documents,
   :partial => "upload_fields",
   :locals => { :doc => Document.new, :index => 'UNIQUE_ID' }

It adds a partial to a div. I need index to be a unique id, but can't
generate one.
I have an actual javascript function next_index() that will return the
next index that works.
Is there any way I can get the return value from that function passed
as the index parameter on the insert_html call? If not, is there any
way I can get a unique id in there?

Thanks for any help!