Observe_field and select_tag

I have this select field:

Access
<%= f.select :access, [‘Global’, ‘Carrier’, ‘Winery’], :prompt =>
“Choose One” %>

being observed by:

<%= observe_field :user_access, :on => ‘blur’,
:url => {:action
=> :find_access}, :frequency => 0.25,
:with => ‘value’ %>

When the user selects an option like ‘Carrier’ I’d like an empty div
to be replaced with a partial of carrier names… I’m doing this with:

page.replace_html :user_options, :partial =>
‘shipper_options’, :object => @shippers

in the find_access.rjs file. My problem is that if I have the select
list open and roll over ‘Carrier’ it does the replace_html on the
div… is there a way to make it wait until the user actually selects
the value ‘Carrier’?

Thanks for any help… this is my first foray into AJAX and I know
this is probably a stupidly simple issue.

SH

shenry wrote:

I have this select field:

Access
<%= f.select :access, [‘Global’, ‘Carrier’, ‘Winery’], :prompt =>
“Choose One” %>

being observed by:

<%= observe_field :user_access, :on => ‘blur’,
:url => {:action
=> :find_access}, :frequency => 0.25,
:with => ‘value’ %>

When the user selects an option like ‘Carrier’ I’d like an empty div
to be replaced with a partial of carrier names… I’m doing this with:

page.replace_html :user_options, :partial =>
‘shipper_options’, :object => @shippers

in the find_access.rjs file. My problem is that if I have the select
list open and roll over ‘Carrier’ it does the replace_html on the
div… is there a way to make it wait until the user actually selects
the value ‘Carrier’?

Thanks for any help… this is my first foray into AJAX and I know
this is probably a stupidly simple issue.

SH

The seleced value transmitted to the server is the current value of your
selectbox. Untill an option is not clicked it is not selected.

I think a better event would be onchange instead of on blur, to trigger
your ajax query. Like that no need to observe the field all the time, so
i’ts better for the app.

I’ve changed the select field to be:

<%= f.select :access, [‘Global’, ‘Carrier’, ‘Winery’], :prompt =>
“Choose One”,
:onchange => remote_function(:url => {:action
=> :find_access}) %>

nothing happens when changing the selection (I don’t see the onchange
in the html source either…)

Should I be coding the javascript manually, rather than using helpers?

thx

SH

On Jul 13, 10:07 pm, nico Itkin [email protected]

D’oh… here is what works =>

<%= f.select :access, [‘Global’, ‘Carrier’, ‘Winery’], {:prompt =>
“Choose One”},
:onchange => remote_function(:url => {:action => :find_access},
:with => “‘value=’ + value”) %>

wasn’t paying attention to the curly braces.

thanks nico,

SH