ajax on load?

Hi,

I have a form with a select box and there is a div under the select
box that gets populated with data collected via ajax, based on the
value selected in the select box. I use an observe field to accomplish
this. It all work pretty well except, let's say, the form gets
submitted (with a value in the select box) and for some reason the
validation fails and after the page refresh( the form submission isnt
ajax), the select box keeps the value that had been selected, however,
since the div underneath only gets populated and shown on a "change"
event, is hidden. I would like it to be showing if there is already a
value in the select box. one thing I can do is simply make an ajax
call when the page loads and populate/show the div, but it would look
awkward (the ajax requests show a shadow box type progress bar, this
is a requirement).

Is there a better way to do this?

Thanks

Since you have the value in your controller and you simply rerender the same views, make your views more intelligent and render the appropriate data at page render right away.

Bad code, but just so you get the idea

<% form_for @record do |f| %>

<% f.select :some_id %>

<% end %>

<% if @record && @record.some_id %>

render view for value with some_id

<% else %>

render default view without any value

<% end %>

Best regards

Peter De Berdt