Fire JS event on page load


#1

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


#2

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


#3

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


#4

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