I am implementing the functionality of cascading drop downs of countries
and states. I want this to be done with Ajax and ruby so that the page
dont get refreshed on selecting the country in first drop down.
Currently I have implemented it with java script and ruby. But the
problem is the page get refreshed when i select the country from
countries drop down. Can some one help me out in implementing this
functionality.
Any help would be greatly appreciated.
-Regards
Ruchita S…
Hi
please tell me the fields of the country,state and users table
collection_select(:country, :country_name, @countries, :id,
:country_name,
here the :country_name after :id is it a field in countries table?
Hi Abhimanyu,
The fields of countries table are id and country_name. The fields of
states table are id, country_id and state_name. The fields of users
table are id, login, first_name,and so on including country_id and
state_id.
I am implementing the functionality of cascading drop downs of countries
and states. I want this to be done with Ajax and ruby so that the page
dont get refreshed on selecting the country in first drop down.
Currently I have implemented it with java script and ruby. But the
problem is the page get refreshed when i select the country from
countries drop down. Can some one help me out in implementing this
functionality.
Any help would be greatly appreciated.
-Regards
Ruchita S…
Hi
please tell me the fields of the country,state and users table
collection_select(:country, :country_name, @countries, :id,
:country_name,
here the :country_name after :id is it a field in countries table?
You havnt closed the double quotes starting before country_name. I hav
tried all the options but it’s not working. Moreover, I am not getting
where to use the second line of code u have send?
My code is as follows:
<%=
collection_select(:country, :country_name, @countries, :id,
:country_name,
options = {:prompt => "– Select a Country –"},
html_options =
{
:onChange => "new Ajax.Updater('dd_cities',
'/user/country_changed/' + this[this.selectedIndex].value,
{asynchronous:true, evalScripts:true});"
}
)
%>
Abhi M. wrote:
Hi
sorry there is no double quotes there
the second line of code is to save the data that you can write after
collection_select itself . But if you want to save states also
There should be a function “selectedData(selectedIndex)” and inside the
function you should have following line
var country_id = selectedIndex
<%= remote_function(:update => ‘dd_cities’, :url => {:action =>“action
name”},:with => “‘value=’+encodeURIComponent(country_id )”)%>
Abhi M. wrote:
Hi
sorry there is no double quotes there
the second line of code is to save the data that you can write after
collection_select itself . But if you want to save states also
be within form tag
Hi,
It’s not working and I have to get it done today only.
If you are still using javascript send me the updated code or else if
you are in hurry then try as Mr Bala has suggested for some time(say 1
hr max) Because its not good to change the flow often . Also javascript
is not that much messy if get used to it. I hope I have not confused you
in our discussions all along
Hi
if drop down is working fine
Please use breakpoint in the controller to check that whether the values
params[:country][:country_name] and
params[:state][:state_name] and let me know
Hi
if drop down is working fine
Please use breakpoint in the controller to check that whether the values
params[:country][:country_name] and
params[:state][:state_name] and let me know
Hi,
Both values are coming right. But the control is not going after
if @user.save… and therefore no data is being saved in the
database. Let me know if if i have done some mistake.
If you are still using javascript send me the updated code or else if
you are in hurry then try as Mr Bala has suggested for some time(say 1
hr max) Because its not good to change the flow often . Also javascript
is not that much messy if get used to it. I hope I have not confused you
in our discussions all along.
Hi,
I am really very confused. I am using javascript code only… dont want
to change the flow. I am sending you the code of view as well as that of
controller. I know what the problem is but really dont hav an idea wat
to do?
The name of view is new_client.rhtml.
<%= javascript_include_tag :defaults %>
<%= show_flashes :notice, :warning %>
Add New Client
Login
Password
Confirm Password
First Name
Last Name
Country
<%=
collection_select(:country, :country_name, @countries, :id,
:country_name,
options = {:prompt => "– Select a Country –"},
html_options =
{
:onChange => "new Ajax.Updater('dd_cities',
'/user/country_changed/' + this[this.selectedIndex].value,
{asynchronous:true, evalScripts:true});"
}
)
%>