Advertisement
yeshuadesign

funções.js

Aug 29th, 2016
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.89 KB | None | 0 0
  1. $(function(){
  2.  
  3. // Pais
  4. function pais(){
  5. $.ajax({
  6. type: 'GET',
  7. url: 'funcoes.php',
  8. data: {
  9. acao: 'pais'
  10. },
  11. dataType: 'json',
  12. success: function(data){
  13. console.log(data);
  14.  
  15. for(i = 0; i < data.qtd; i++){
  16. $('select[name=pais]').append('<option value="'+data.id[i]+'">'+data.pais[i]+'</option>');
  17. }
  18. }
  19. });
  20. }
  21. pais();
  22.  
  23. // Estado
  24. function estado(pais){
  25. $.ajax({
  26. type: 'GET',
  27. url: 'funcoes.php',
  28. data: {
  29. acao: 'estado',
  30. id: pais
  31. },
  32. dataType: 'json',
  33. beforeSend: function(){
  34. $('select[name=estado]').html('<option>Carregando...</option>');
  35. },
  36. success: function(data){
  37. $('select[name=estado]').html('');
  38. $('select[name=estado]').append('<option>Selecione o estado</option>');
  39. for(i = 0; i < data.qtd; i++){
  40. $('select[name=estado]').append('<option value="'+data.id[i]+'">'+data.estado[i]+'</option>');
  41. }
  42. }
  43. });
  44. }
  45.  
  46.  
  47. // Cidade
  48. function cidade(estado){
  49. $.ajax({
  50. type: 'GET',
  51. url: 'funcoes.php',
  52. data: {
  53. acao: 'cidade',
  54. id: estado
  55. },
  56. dataType: 'json',
  57. beforeSend: function(){
  58. $('select[name=cidade]').html('<option>Carregando...</option>');
  59. },
  60. success: function(data){
  61. $('select[name=cidade]').html('');
  62. $('select[name=cidade]').append('<option>Selecione a cidade</option>');
  63. for(i = 0; i < data.qtd; i++){
  64. $('select[name=cidade]').append('<option value="'+data.id[i]+'">'+data.cidade[i]+'</option>');
  65. }
  66. }
  67. });
  68. }
  69.  
  70.  
  71. $('select[name=pais]').change(function(){
  72. $('select[name=cidade]').val($("select[name=cidade] option:first-child").val());
  73. var id = $(this).val();
  74. estado(id);
  75. });
  76.  
  77. $('select[name=estado]').change(function(){
  78. var idEstado = $(this).val();
  79. cidade(idEstado);
  80. });
  81.  
  82. $('select[name=cidade]').change(function () {
  83. $('#1').fadeIn(2000);
  84. });
  85.  
  86. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement