Ajax Help: Multiple Updates -?

Hi!

Wondering if anyone can tell me what’s wrong with my code?

I’m trying to use the onChange event of a select list to update multiple
divs…

Agile Web D. with Rails (p. 403) suggests using “:complete =>
eval(request.responseText) instead of :update”

I’ve attempted the following test code:

in the view

<select name=“plist”, class=“required”, onchange=“<%=
remote_function(:complete => evaluate_remote_response, :url => { :action
=> :updateDivs }) %>” >

Select a Person Select a Dog Select a Frog



controller

def updateDivs
    render(:layout => false)
end

updateDivs.rhtml

<%= javascript_tag(

update_element_function(
“detail1”, :position => :top, :content => “testData1” ) +

update_element_function(
“detail2”, :position => :top, :content => “testData2” ) +

update_element_function(
“detail3”, :position => :top, :content => “testData3” ) +

update_element_function(
“detail4”, :position => :top, :content => “testData4” )) %>

I don’t get any errors, but the testdata is not inserted into the divs
either.

The example in the book replaces the :update with a :complete, but this
is done on a “link_to_remote()” not on a “remote_function()” as I have
done… I assumed that this would be OK because the documentation says
that remote_function “Takes the same arguments as link_to_remote”?!?

Just for grins I tried adding the following:

 <%= link_to_remote "Try Me",
  :complete => "eval(request.responseText)",
  :url => { :action => :updateDivs } %>

Again, no errors, but no output!

Both the link & the select onchange fire the updateDivs method & produce
exactly the same log output for both:

link/“Try Me” log output:
Processing TestemController#updateDivs (for 127.0.0.1 at 2005-12-23
22:41:17) [POST]
Parameters: {“action”=>“updateDivs”, “controller”=>“testem”}
Rendering testem/updateDivs
Completed in 0.01366 (73 reqs/sec) | Rendering: 0.00871 (63%) | 200 OK
[http://localhost/testem/updateDivs]

Select/onChange log output:
Processing TestemController#updateDivs (for 127.0.0.1 at 2005-12-23
22:41:23) [POST]
Parameters: {“action”=>“updateDivs”, “controller”=>“testem”}
Rendering testem/updateDivs
Completed in 0.00775 (129 reqs/sec) | Rendering: 0.00353 (45%) | 200 OK
[http://localhost/testem/updateDivs]

Any help would be appreciated, I’m really stuck!

Thanks!

randy marmer wrote:

update_element_function(
“detail3”, :position => :top, :content => “testData3” ) +

update_element_function(
“detail4”, :position => :top, :content => “testData4” )) %>

I don’t get any errors, but the testdata is not inserted into the divs
either.

Get rid of the “javascript_tag” wrapper. The remote response is being
evaluated, so you don’t want to rap it in tags.


We develop, watch us RoR, in numbers too big to ignore.

Mark Reginald J. wrote:

randy marmer wrote:

update_element_function(
“detail3”, :position => :top, :content => “testData3” ) +

update_element_function(
“detail4”, :position => :top, :content => “testData4” )) %>

I don’t get any errors, but the testdata is not inserted into the divs
either.

Get rid of the “javascript_tag” wrapper. The remote response is being
evaluated, so you don’t want to rap it in tags.

INDEED! Thanks!