# Updating a Text box

**URL:** <https://www.ruby-forum.com/t/updating-a-text-box/170787>\
**Category:** Rails\
**Created:** [June 22, 2009, 8:52pm UTC](https://www.ruby-forum.com/t/updating-a-text-box/170787 "2009-06-22T20:52:41Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![fireknite](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/6bbea6/32.png) [@fireknite](https://www.ruby-forum.com/u/fireknite)\
**Post date:** [June 22, 2009, 8:52pm UTC](https://www.ruby-forum.com/t/updating-a-text-box/170787/1 "2009-06-22T20:52:41Z")

</div>

I have a page with a collection\_select, populated by an array of info  
pulled form a MySQL table. Trying to get some text\_fields to update  
with information from this array depending on which item was selected  
from the collection select.

Here is some view code:

\<%= collection\_select(:person, :convert, @nonUsers, :id, :fullName,  
{:prompt =\> “Choose…”}, :style =\> “width:125px;”) %\>  
\<%= text\_field\_tag :userName, @userName %\>  
\<%= observe\_field “person\_convert”, :function =\> update\_page {|page|  
page[“userName”].value = @nonUsers[2].fullName }%\>

Which will populate the list with HTML as follows:

Person 1 Person 2 Person 3

Currently, with the @nonUsers[2].fullName section i’m able to get the  
text\_field to populate with the fullName of the second item, but i’m  
struggling as to make this dynamic. Please help.

---

<div class="post-metadata">

**Author:** ![fireknite](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/6bbea6/32.png) [@fireknite](https://www.ruby-forum.com/u/fireknite)\
**Post date:** [June 22, 2009, 10:24pm UTC](https://www.ruby-forum.com/t/updating-a-text-box/170787/2 "2009-06-22T22:24:28Z")

</div>

On Jun 22, 7:52 pm, Matt Y. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> \<%= observe\_field “person\_convert”, :function =\> update\_page {|page|  
> struggling as to make this dynamic. Please help.  
> Your rjs (ie update\_page) is just generating a static blob of  
> javascript, it’s much easier to get rid of that crutch and just write  
> the javascript yourself, something like $(‘userName’).value = $F  
> (‘person\_convert’) (assuming you are using prototype).

Fred
