Salil Gaikwad
2009-Oct-09 12:27 UTC
get value of select whch change using ajax after form submit
Hi All, I have a problem while updating select list using ajax and then submit it. what i have done is to change the drop down of a city when i changed the state.but when i am submitting the form i am not able to get the value of city. Following is my code for the same. edit.html.erb <% form_for :user_info , :url=>{:controller=>"users", :action=>"update_contact_details",:id=>params[:id] } do |f| %> <% @state= UsaCity.find_by_sql(''select DISTINCT state from usa_cities'') %> <tr> <td >State</td> <td> <%= select_tag ''user_info[state]'', options_from_collection_for_select(@state, :state, :state, @user_info.state) %><div id="user_sate_loading" style="display:none"><img src="/images/loading.gif"></div> <br><span id="stateError" class="error"></span> <%= observe_field :user_info_state, :url =>{:controller=>"logins",:action =>''select_city'', :id=>''1''}, :update=> ''city'' , :with => "'' state=''+document.getElementById(''user_info_state'').value+''&type=contact_details''", :on=>''click'' %> </td> </tr> <tr id="city"> <td >City</td> <td><%= collection_select :user_info, :city, @cities || Array.new, :city, :city, :prompt=>true %><br><span id="cityError" class="error"></span></td> </tr> <% end %> controller method def edit_city @cities = UsaCity.find(:all, :conditions=>["state=?", params[:state]]) @type = params[:type] render :update do |page| page.replace_html ''city'', :partial => ''logins/select_city'', :object=>[@cities, @type], :layout => false end end _select_city.html.erb <td>City1345</td> <td><%= collection_select :user_info, :city, @cities || Array.new, :city, :city, :prompt=>true %><br><span id="cityError" class="error"></span></td> Regards, Salil Gaikwad -- Posted via http://www.ruby-forum.com/.
Salil Gaikwad
2009-Oct-09 13:06 UTC
Re: get value of select whch change using ajax after form submit
Hi All, Sorry for this but it''s not working properly because i use form_for tag inside the <table> tag. i only remove form from inside the table and keep outside the table tag and now everything is works like a magic. I hope this will help someone to save his/her 1 hr or 2. Regards, Salil Gaikwad -- Posted via http://www.ruby-forum.com/.