I’m new to rails/ruby having come from PHP and am just starting to get
my head round how easy it can be
However, can anyone point me in the right direction for dynamicaly
updating a select box based upon the choice of a previous select box,
without a page refresh.
Using RJS calls with an observe_field is the way to go. Works great in
FF
but you cannot do this in IE by using RJS alone. The reason is that RJS
uses the innerHTML method to replace content with a page.html_replace
call.
IE does not support the innerHTML call on select boxes. You would need
to
implement it in javascript completely.
The only way that I can think of (maybe) is to use a javascript array
and
update the array from an RJS call.
Using RJS calls with an observe_field is the way to go. Works great in
FF but you cannot do this in IE by using RJS alone. The reason is that
RJS uses the innerHTML method to replace content with a
page.html_replace call. IE does not support the innerHTML call on
select boxes. You would need to implement it in javascript completely.
Or rip out the whole select box and replace it, rather than just the
option list.
I did try to rip out the entire select box and replace it, but for some
reason that I still havn’t worked out, once I replaced the select box,
the
observe_field didn’t work anymore so my next box (I had 3) was never
going
to update.
I did try to rip out the entire select box and replace it, but for
some reason that I still havn’t worked out, once I replaced the
select box, the observe_field didn’t work anymore so my next box (I
had 3) was never going to update.
Here is one way that we have been doing dynamic select boxes. Maybe
this helps you a bit.
I have a working code where there are only 2 select boxes i.e.
populating city when state is selected. I am having issues with
populating locality based on selected city. Working with 2 dynamic
select is straight forward. Working with more than 2 dynamic/cascading
select box is a real issue.
I am experiencing problems retrieving information from the related drop
downs.
I can save information in the database (i.e. state_id and city_id are
getting saved in the Address table).
However on the Address’s edit/update screen, the information from the
first “State” drop down is getting retrieved
properly but nothing is getting displayed in the second drop down -
“City”.
I am using observe fields to retrieve data for the second drop down.
Please advise how to prepopulate information for the second drop down
based on the “id” stored in the database on Edits screens.
Thanks in advance for your help!
I
Ramanan wrote:
Kevin O. wrote:
On Saturday, August 19, 2006, at 12:00 AM, Ramanan wrote:
I have a working code where there are only 2 select boxes i.e.
populating city when state is selected. I am having issues with
populating locality based on selected city. Working with 2 dynamic
select is straight forward. Working with more than 2 dynamic/cascading
select box is a real issue.
I am using observe fields to retrieve data for the second drop down.
On Saturday, August 19, 2006, at 12:00 AM, Ramanan wrote:
Take a look at this…
select is straight forward. Working with more than 2 dynamic/cascading
select box is a real issue.
Article includes a demo, source code, explanations. The page that
actually retrieves the db data will need to be in your web language of
choice, of course.