Creating AJAX on the fly

I have two drop-down menus in a page.

the first has only two values, and when one of those two values is
selected, an AJAX call is made to RoR.

there, I fetch some rows from the database, and fill the second
drop-down menu.

but, from this second drop-down menu, I also want to make another AJAX
call and fill some data in a Div.

The second drop-down menu fills correctly, but never fires the AJAX

First I thought it was because the second drop-down menu didn’t exist in
the page, and the second observer couldn’t find in when the page was

For testing purposes, I created also the second pop-up with some
ficticious data, and the AJAX call worked, so I suppose the second
observer is working as expected.

Also I updated this false second drop-down menu with the new one, coming
from the first AJAX call, but the same as before, this drop-down menu
never fires the AJAX call.

I’m sure the id of the select is good.

What I’m thinking, is that an observer that has to observ a not yet
created object, maybe can’t work, and no matter if the object existed,
because when the first AJAX call replaces the other, even with the same
id, it also dosn’t.

So, my workaround is creating the second drop-down menu with the option

This method works, when a new item is selected from the second menu, the
javascript method fires, but I don’t know how to make a call using AJAX,
I’m using this but I don’t know how to update only a

‘function year_function()
var popup = document.getElementById(“user_year”);
location.href = ("/user/change_year?year="+popup.value) ;

=> any clue on how to send the response to an object, like a Div, …?

I know this question is more for an AJAX forum, but as I’m creating with
the RoR helpers …




hello again,

finally I found link_to_remote() wich solves the problem a little.

instead of crating a new drop-down menu with the customers found, I
created a

and link_to_remote each row. as the rows can be large,
I’d prefer a drop-down menu …

If anyone knows how to generate by code an instance of a drop-down menu
with an observer …




hello again …

well, finally works !!!

the observer must be in the same

as the drop-down menu, so when
RoR loads the new drop-down menu, at the end I create the observer, in a
_view.rhtml page …

it works !!



This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs