Forum: Ruby on Rails fire JS event on page load

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
John B. (Guest)
on 2008-11-28 17:23
Hi,

I have a drop down select which fires an ajax call once selected.
So when i select anything in the email_seperator drop down it fisre the
ajax event below.

<%= observe_field('email_seperator',
        :on => 'click',
        :url => {:controller => 'possible_emails', :action =>
'update_email'},
        :with => "'email_seperator='+$F('email_seperator')",
        :before  => "Element.show('spinner')",
        :success => "Element.hide('spinner')") %>

What i want is when the page first loads for this ajax event to fire
once so the correct information is diaplyed.  Ive tried something like
the below but it works for focus but not for click

<%= javascript_tag render(:update) { |page|
page['email_seperator'].focus } %>

<%= javascript_tag render(:update) { |page|
page['email_seperator'].click } %>

Can anyone help??

JB
Bill W. (Guest)
on 2008-11-28 21:58
(Received via mailing list)
Hi John,

John B. wrote:
>         :before  => "Element.show('spinner')",
>         :success => "Element.hide('spinner')") %>
>
> What i want is when the page first loads for this ajax event to fire
> once so the correct information is diaplyed.

What does 'so the correct information is displayed [sic]' mean?  If you
mean
you want to give the dropdown an initial value, options_for_select lets
you
specify the selected value.  See the documentation for that method and
the
ones that follow it at api.rubyonrails.org.

HTH,
Bill
John B. (Guest)
on 2008-11-29 12:34
Bill W. wrote:
> Hi John,
>
> John B. wrote:
>>         :before  => "Element.show('spinner')",
>>         :success => "Element.hide('spinner')") %>
>>
>> What i want is when the page first loads for this ajax event to fire
>> once so the correct information is diaplyed.
>
> What does 'so the correct information is displayed [sic]' mean?  If you
> mean
> you want to give the dropdown an initial value, options_for_select lets
> you
> specify the selected value.  See the documentation for that method and
> the
> ones that follow it at api.rubyonrails.org.
>
> HTH,
> Bill

Yes i have the correct value displaying in the drop down but this then
fires an ajax request when clicked to update some components on the
view. Id like to automaticall fire this event when the page loads??

JB
Hassan S. (Guest)
on 2008-11-29 18:53
(Received via mailing list)
On Sat, Nov 29, 2008 at 2:34 AM, John B.
<removed_email_address@domain.invalid> wrote:

> Yes i have the correct value displaying in the drop down but this then
> fires an ajax request when clicked to update some components on the
> view. Id like to automaticall fire this event when the page loads??

That -- rendering a page and immediately changing it -- makes no
sense at all; why are you not delivering your page with the proper
initial state?

--
Hassan S. ------------------------ removed_email_address@domain.invalid
This topic is locked and can not be replied to.