Onchange, select, and Ajax

I’m trying to have a select form where users select a state, and once
they do that, another select list appears with all the colleges in that
state.

I got it to work using a form_remote_tag, but that required the user to
select their state, then hit a submit button. Is there a good way to do
this using something like :onchange?

Here is the beginning of my first select:

The problem is, I’m checking in “get_schools” and the state is not
getting passed in. How do I pass it in?

Joe P. wrote:

I’m trying to have a select form where users select a state, and once
they do that, another select list appears with all the colleges in that
state.

I got it to work using a form_remote_tag, but that required the user to
select their state, then hit a submit button. Is there a good way to do
this using something like :onchange?

Here is the beginning of my first select:

The problem is, I’m checking in “get_schools” and the state is not
getting passed in. How do I pass it in?

Still having some problems with this. Can’t seem to pass the value of
the select form into the “get_schools” function.

Hi Joe,

I’d recommend you pick up Cody F.'s RJS tutorial at O’Reilly. I’ll
put
you on the right track. The way you’re mixing Rails/Ruby with HTML/JS,
Rails can’t tell what to do with the pieces you’re giving it.

hth,
Bill

Thanks, I figured it out a couple days ago though :slight_smile:

Even added a little highlight feature.

<select id = “what_state” name=“state” onChange="<%= remote_function(
:update => ‘colleges’,
:url => { :action =>
‘get_schools’},
:with => “‘state=’+value”,
:complete => “new
Effect.Highlight(‘college’,{duration: 2.0,
startcolor:
#00FFCC’,
endcolor: ‘#333333’,
restorecolor:
#333333’})” ) %>">

Joe P. wrote:

I’m trying to have a select form where users select a state, and once
they do that, another select list appears with all the colleges in that
state.

Hi Joe:

Use observe_field for changes to the select to render a new select via a
partial.

see the RDoc - http://api.rubyonrails.com/ for Prototype Helpers

and this article - http://www.roryhansen.ca/?p=9

Cheers,
divotdave

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs