Skip to content

Instantly share code, notes, and snippets.

@abhianair
Last active December 4, 2018 04:34
Show Gist options
  • Save abhianair/6a3389bd2b0f76b832ae70e69f1c5627 to your computer and use it in GitHub Desktop.
Save abhianair/6a3389bd2b0f76b832ae70e69f1c5627 to your computer and use it in GitHub Desktop.
Update Country code field upon selecting Country field using AJAX
$(document).ready(function(){
$("#id_country_code").change(function(){
var option = $(this).val();
$.ajax({
type: "GET",
url: "/models/get",
data:{
key: option
},
success: function(response){
if(response.phone)
$("#phone").val(response.phone);
}
})
});
});
@c = params[:key]
@c = ISO3166::Country.new(@c)
@c = @c.country_code
@c = "+#{@c}"
render json: {:phone => @c}
resources :models do
collection do
get 'get'
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment