# Select Box Question

**URL:** <https://www.ruby-forum.com/t/select-box-question/101820>\
**Category:** Rails\
**Created:** [August 8, 2006, 6:19am UTC](https://www.ruby-forum.com/t/select-box-question/101820 "2006-08-08T06:19:51Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Shanan\_S](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/0ea827/32.png) [@Shanan\_S](https://www.ruby-forum.com/u/Shanan_S)\
**Post date:** [August 8, 2006, 6:19am UTC](https://www.ruby-forum.com/t/select-box-question/101820/1 "2006-08-08T06:19:51Z")

</div>

Hi,

Yet another newbie here… I’m writing an appliction in Rails, and I’ve  
Ajaxified my select boxes so they update dynamically. I used the  
“observe\_field” method to monitor changes to my select box. I find that  
it’s kind of erratic… it updates constantly and makes the selection  
for me, based on where my mouse happens to be hovering when it does its  
observation. Not very user friendly. I’d much rather the onChange  
event, but I’m not sure exactly how to write the syntax for using the  
event.

Here’s my code as it is now:

 \<%= options\_from\_collection\_for\_select( Product.find\_all, "proddesc\_pk", "prod\_name" ) %\> \<%= observe\_field("product[proddesc\_pk]", :frequency =\>0.25, :update =\> "component\_id\_list", :url =\> { :action =\> :fill\_component\_box}, :with =\> "'id='+value") %\>

How would I go about changing that code so that it updates based on an  
onChange event, rather than the observation?

Any help would be greatly appreciated!

Thanks,  
~ Shanan

–  
Shanan S. | removed\_email\_address@domain.invalid | (602) 357-4327 (x51609)  
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=  
“Crucify the ego before it’s far too late  
And leave behind this place so negative and blind and cynical  
And you will come to find that we are all one mind  
Capable of all that’s imagined and all conceivable”  
- Maynard James Keenan, Tool

---

<div class="post-metadata">

**Author:** ![Shanan\_S](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/0ea827/32.png) [@Shanan\_S](https://www.ruby-forum.com/u/Shanan_S)\
**Post date:** [August 8, 2006, 5:30pm UTC](https://www.ruby-forum.com/t/select-box-question/101820/2 "2006-08-08T17:30:08Z")

</div>

Shanan S. wrote:

> %\>
> 
> How would I go about changing that code so that it updates based on an  
> onChange event, rather than the observation?

Just get rid of the :frequency parameter.

–  
We develop, watch us RoR, in numbers too big to ignore.

---

<div class="post-metadata">

**Author:** ![Shanan\_S](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/0ea827/32.png) [@Shanan\_S](https://www.ruby-forum.com/u/Shanan_S)\
**Post date:** [August 15, 2006, 2:22pm UTC](https://www.ruby-forum.com/t/select-box-question/101820/3 "2006-08-15T14:22:05Z")

</div>

On Aug 7, 2006, at 11:12 AM, Shanan S. wrote:

> ```
> :url => { :action => :fill_component_box},
> 
> ```

Here is how you can use the onchange event which is much nicer to  
work with:

```
			  <%= select_tag( 'product[proddesc_pk]',
			                    options_from_collection_for_select(

```

Product.find\_all, “proddesc\_pk”, “prod\_name”) ,  
:onchange =\> remote\_function(:with =\>  
“‘proddesc\_pk =’+value”,  
:loading =\> “Element.show(‘loading-indicator1’)”,  
:url =\> { :action =\> :  
fill\_component\_box } ) %\>

Doing it that way will put the value in params[: proddesc\_pk] for  
you . You can then respond with rjs to fill whatever you need to fill.

Cheers-  
-EZra
