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.
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 Ruchita,
In Ajax the main advantage is that we can refresh the page in parts ie,
buy defining divisions in view file as
and updating only this div as :update => "some name"
But at this juncture what I feel is that it is not due to abscence of
Ajax but it is due to your code logic that the page is refreshing while
selecting country only. Any way may be I can help you if you can send me
some code especially that part where you implement drop down list
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 Ruchita,
In Ajax the main advantage is that we can refresh the page in parts ie,
buy defining divisions in view file as
and updating only this div as :update => "some name"
But at this juncture what I feel is that it is not due to abscence of
Ajax but it is due to your code logic that the page is refreshing while
selecting country only. Any way may be I can help you if you can send me
some code especially that part where you implement drop down list
All the Best
Hi Abhi M.,
The part of the code where i am implementing it as follows. Can you plz
tell me where is the problem.
First Name
Last Name
Country
<% @countries.each do |country| %>
>
<%= country.country_name %>
<% end %>
ie whenever there is a change in country dropdown selection list control
should go to function goToSub() which inturn will load the other part
rt?. So that is why it is getting refreshed
ie whenever there is a change in country dropdown selection list control
should go to function goToSub() which inturn will load the other part
rt?. So that is why it is getting refreshed
I will check some solution and get back to you
Thanks
Abhimanyu
Yeah… In function goToSub(); I am fetching the value of country id.
window.location="…/user/new_client?categoryid=" +
category2.options[category2.selectedIndex].value;
Then i am getting this id by using this line of code:
<% @rubyVar=request.parameters[“categoryid”] %>
In the states drop down i am comparing:
if (state.country_id == (@rubyVar.to_i))
then corresponding to this, states are displayed.
The problem is whenever I select the country, the fields which are above
the country are lost perhaps due to refreshing of page.
ie whenever there is a change in country dropdown selection list control
should go to function goToSub() which inturn will load the other part
rt?. So that is why it is getting refreshed
I will check some solution and get back to you
Thanks
Abhimanyu
Hi Ruchita
Sorry I have to reach some place. so I will post you tommorrow only.
Also try to use Collection_select instead of “option” to show drop down
list so that you can include many options. check some tutorials on
collection_select if you dont know that or else I will tell you tomorrow
Thanks
Abhimanyu
Hi
Thanks a lot. Not an issue but please do help me out.
ie whenever there is a change in country dropdown selection list control
should go to function goToSub() which inturn will load the other part
rt?. So that is why it is getting refreshed
I will check some solution and get back to you
Thanks
Abhimanyu
Hi Ruchita
Sorry I have to reach some place. so I will post you tommorrow only.
Also try to use Collection_select instead of “option” to show drop down
list so that you can include many options. check some tutorials on
collection_select if you dont know that or else I will tell you tomorrow
Hi,
I have given only some idea to you. Its not part of any code . You can
use collection select for drop down list
and if any country is selected then javascript function function
selectedData(selectedvalue) is called. In that function itself it will
call other action
function selectedData(selectedvalue)
{
var stateid = selectedvalue;
<%= remote_function(:update => ‘show’, :action =>
action_name,:with => “‘value=’+encodeURIComponent(stateid)”)%>
}
write the state drop down list in a partial file and render that file in
the above action you call
and also define a div called show in the view file of country drop down
and render the partial file here also.
Hi,
I have given only some idea to you. Its not part of any code . You can
use collection select for drop down list
and if any country is selected then javascript function function
selectedData(selectedvalue) is called. In that function itself it will
call other action
function selectedData(selectedvalue)
{
var stateid = selectedvalue;
<%= remote_function(:update => ‘show’, :action =>
action_name,:with => “‘value=’+encodeURIComponent(stateid)”)%>
}
write the state drop down list in a partial file and render that file in
the above action you call
and also define a div called show in the view file of country drop down
and render the partial file here also.
Please try this
Okie… let me try to implement this. Thanks for your help. I’ll get
back to you.
Yes Please send me the code. You can use the foreign keys as you
sent.Some times I wont be able to reply today . May be between morning
and evening we can have discussion.
Are you a student . I asked because If you are free other times we can
have discussion then. I will be leaving after a short while
THANKS
ABHIMANYU
Hi,
I have given only some idea to you. Its not part of any code . You can
use collection select for drop down list
and if any country is selected then javascript function function
selectedData(selectedvalue) is called. In that function itself it will
call other action
function selectedData(selectedvalue)
{
var stateid = selectedvalue;
<%= remote_function(:update => ‘show’, :action =>
action_name,:with => “‘value=’+encodeURIComponent(stateid)”)%>
}
write the state drop down list in a partial file and render that file in
the above action you call
and also define a div called show in the view file of country drop down
and render the partial file here also.
Please try this
Okie… let me try to implement this. Thanks for your help. I’ll get
back to you.
Thanks a lot for your help. I have implemented the drop downs. Now the
problem is I have to save the data of the country and state in the users
table. I dont know how to save the country and state in the database
because i am fetching the data from the countries and states table but i
have to make it save in users table.
Yes Please send me the code. You can use the foreign keys as you
sent.Some times I wont be able to reply today . May be between morning
and evening we can have discussion.
Are you a student . I asked because If you are free other times we can
have discussion then. I will be leaving after a short while
THANKS
ABHIMANYU
Hi
<%=
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});"
}
)
%>