Hello ,
Use an Observe_field , so that you can have the country selected as a
parameter and with the help of the country name u can extract the respective
cities from the database
The following is the code snippet I have used. Might be of some help to u.
My View Code:
----------------------
<%= form_remote_tag(:update =>"update_div", :url => { :action => :register}
) %>
<p>
<label for = "country">Country</label> <br />
<%= select_tag id="user_country",
country_options_for_select(selected = nil,
priority_countries = ["Select One", "India", "USA", "Pakistan",
"Nepal", "China"]) %>
</p>
<%= observe_field("user_country", :url => { :controller => "login",
:action => "check_state"}, :update => "update_list", :with => "country")%>
<div id ="update_list" >
<p>
<label for = "state">State</label> <br />
<%= select("user",:state, %w{ -- }, :class => "select_state") %>
</p>
</div>
</form>
Controller Code:
----------------------------
def check_state
@result = Country.find(:all, :conditions => [ "country = ?",
params[:country] ] )
render :partial => 'states', :layout => false
end
My Partial Code: (To update the states combo box div)
------------------------------------------------------------------------------
<%= stylesheet_link_tag 'css_type1.css' %>
<p>
<label for="state">State </label>
<br/>
<%= select_tag(id= "user_state",
options_from_collection_for_select(@result,"state", "state")) %>
</p>
Thanks & Regards,
Saideep Annadatha
On Sun, Oct 5, 2008 at 3:44 PM, Jay Pangmi <[EMAIL PROTECTED]
> wrote:
>
> Hi, I have two combo boxes. One combo box has the name of countries
> stored in the database. So, when a country is selected from this combo
> box I want other combo box to list all the cities stored in the database
> related to that selected country without clicking any button. Any help
> would be great.. thanks
> --
> Posted via http://www.ruby-forum.com/.
>
> >
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby
on Rails: Talk" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---