# Select boxes

**URL:** <https://www.ruby-forum.com/t/select-boxes/130330>\
**Category:** Rails\
**Created:** [February 27, 2008, 1:09pm UTC](https://www.ruby-forum.com/t/select-boxes/130330 "2008-02-27T13:09:43Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![brian](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/97f17d/32.png) [@brian](https://www.ruby-forum.com/u/brian)\
**Post date:** [February 27, 2008, 1:09pm UTC](https://www.ruby-forum.com/t/select-boxes/130330/1 "2008-02-27T13:09:43Z")

</div>

I am trying to understand the best way to apply javascript to two  
select boxes. If the user changes the selection in box A, a given  
option in box B would dynamically become selected.

Does rails provide help with tasks like this, or would I need to  
manually create a javascript function to handle this kind of thing in  
the view?

---

<div class="post-metadata">

**Author:** ![brian](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/97f17d/32.png) [@brian](https://www.ruby-forum.com/u/brian)\
**Post date:** [February 27, 2008, 1:32pm UTC](https://www.ruby-forum.com/t/select-boxes/130330/2 "2008-02-27T13:32:41Z")

</div>

On 27 Feb 2008, at 12:09, Brian wrote:

> I am trying to understand the best way to apply javascript to two  
> select boxes. If the user changes the selection in box A, a given  
> option in box B would dynamically become selected.
> 
> Does rails provide help with tasks like this, or would I need to  
> manually create a javascript function to handle this kind of thing in  
> the view?

Whatever you do boils down to writing an onchange handler for A. You  
can do this in a railsish way: you can use the update page to let you  
write that bit of javascript using rjs, but I would contend that there  
isn’t a huge amount of point doing it that way. With a smattering of  
prototype, javascript really isn’t that bad.

Fred
