# Auto refreshing a page based on select change

**URL:** <https://www.ruby-forum.com/t/auto-refreshing-a-page-based-on-select-change/51765>\
**Category:** Rails\
**Created:** [January 6, 2006, 9:00pm UTC](https://www.ruby-forum.com/t/auto-refreshing-a-page-based-on-select-change/51765 "2006-01-06T21:00:58Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![danielb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/c57346/32.png) [@danielb](https://www.ruby-forum.com/u/danielb)\
**Post date:** [January 6, 2006, 9:00pm UTC](https://www.ruby-forum.com/t/auto-refreshing-a-page-based-on-select-change/51765/1 "2006-01-06T21:00:58Z")

</div>

Hi all,

I have a select helper form on a web page which contains a list of  
dates. When  
the user selects a date, one of the other forms on the page needs to be  
updated  
based on the newly selected date.

Is there a way to catch this event in Rails? Are we talking Ajax here?  
Or is  
there a simpler way?

Thanks,

Dan

---

<div class="post-metadata">

**Author:** ![danielb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/c57346/32.png) [@danielb](https://www.ruby-forum.com/u/danielb)\
**Post date:** [January 6, 2006, 9:22pm UTC](https://www.ruby-forum.com/t/auto-refreshing-a-page-based-on-select-change/51765/2 "2006-01-06T21:22:59Z")

</div>

Daniel B. wrote:

> Hi all,
> 
> I have a select helper form on a web page which contains a list of  
> dates. When  
> the user selects a date, one of the other forms on the page needs to be  
> updated  
> based on the newly selected date.
> 
> Is there a way to catch this event in Rails? Are we talking Ajax here?  
> Or is  
> there a simpler way?
> 
> Thanks,
> 
> Dan

You could use a ‘onchange()’ script with your select dropdown and  
postback a parameter that updates the other field.

Not too difficult, but not as slick as an AJAX solution.

---

<div class="post-metadata">

**Author:** ![danielb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/c57346/32.png) [@danielb](https://www.ruby-forum.com/u/danielb)\
**Post date:** [January 6, 2006, 10:52pm UTC](https://www.ruby-forum.com/t/auto-refreshing-a-page-based-on-select-change/51765/3 "2006-01-06T22:52:12Z")

</div>

Kevin O. wrote:

> > Is there a way to catch this event in Rails? Are we talking Ajax here?
> 
> Not too difficult, but not as slick as an AJAX solution.

Thanks Kevin, but I’m not sure how that should look exactly.

\<%=  
select(:var, :attr, choices, :options =\> {:onchange =\> })  
%\>

I’m having trouble following the docs. Please help.

Thanks,

Dan

---

<div class="post-metadata">

**Author:** ![danielb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/c57346/32.png) [@danielb](https://www.ruby-forum.com/u/danielb)\
**Post date:** [January 6, 2006, 11:24pm UTC](https://www.ruby-forum.com/t/auto-refreshing-a-page-based-on-select-change/51765/4 "2006-01-06T23:24:35Z")

</div>

Take a look at this…

[http://www.faqs.org/docs/htmltut/forms/\_SELECT\_onChange.html](http://www.faqs.org/docs/htmltut/forms/_SELECT_onChange.html)

---

<div class="post-metadata">

**Author:** ![danielb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/c57346/32.png) [@danielb](https://www.ruby-forum.com/u/danielb)\
**Post date:** [January 12, 2006, 5:32am UTC](https://www.ruby-forum.com/t/auto-refreshing-a-page-based-on-select-change/51765/5 "2006-01-12T05:32:03Z")

</div>

On 1/7/06, Kevin O. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > Is there a way to catch this event in Rails? Are we talking Ajax here?  
> > Or is  
> > there a simpler way?
> > 
> > Thanks,
> > 
> > Dan
> 
> You could use a ‘onchange()’ script with your select dropdown and  
> postback a parameter that updates the other field.

Why cant you do Ajax.updater () for the onchange() event? That would be  
AJAX  
right ?  
There is an example at  
[http://www.roryhansen.ca/?p=9](http://www.roryhansen.ca/?p=9)  
which uses the observer but I was thinking why not use the onchange  
insted  
of the observer?

Not too difficult, but not as slick as an AJAX solution.

---

<div class="post-metadata">

**Author:** ![danielb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/c57346/32.png) [@danielb](https://www.ruby-forum.com/u/danielb)\
**Post date:** [January 16, 2006, 3:06pm UTC](https://www.ruby-forum.com/t/auto-refreshing-a-page-based-on-select-change/51765/6 "2006-01-16T15:06:52Z")

</div>

Thanks Kewin!!

Your link:

> [HTML onChange - HTML Code Tutorial](http://www.faqs.org/docs/htmltut/forms/_SELECT_onChange.html)

helped me solve a problem that’s I’ve been trying to fix since before  
christmas. Nice one.
