Advertisement
Guest User

Untitled

a guest
May 20th, 2019
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.80 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <title>Ma page test</title>
  5. <meta name="title" content="Ma super page" />
  6. <meta charset="utf-8" />
  7. <link rel="stylesheet" type="text/css" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" />
  8. <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.js" type="text/javascript"></script>
  9. <style>
  10. body {
  11. background-color: #21d6ff;
  12. }
  13. .container {
  14. margin-top: 5px;
  15. border-radius: 3px;
  16. background-color: white;
  17. min-height: 800px;
  18. padding-top: 10px;
  19. padding-bottom: 10px;
  20. }
  21. .title {
  22. text-align: center;
  23. color: dodgerblue;
  24. }
  25. .form-code {
  26. margin-top: 50px;
  27. width: 400px;
  28.  
  29. }
  30. .ville {
  31. margin-top: 5px;
  32. border: 1px solid lightgray;
  33. border-radius: 3px;
  34. }
  35.  
  36. .link {
  37. margin-top: 10px;
  38. display: none;
  39. }
  40. </style>
  41. <script>
  42. let divResult;
  43. let divLink;
  44. let result;
  45. $(document).ready(() => {
  46. divResult = document.getElementById('result');
  47. divLink = document.getElementById('link');
  48. });
  49. function getCommunes(event) {
  50. $.get('https://geo.api.gouv.fr/communes', {nom: event.target.value}, value => {
  51. result = value;
  52. divResult.innerHTML = '';
  53. getResult();
  54. });
  55. }
  56. function getResult() {
  57. for (value of result.splice(0, 5)) {
  58. divResult.innerHTML += `<div class="ville">
  59. Nom: ${value.nom}
  60. Code Postal: ${value.codesPostaux.join(' ')}
  61. Departement: ${value.codeDepartement}
  62. Population: ${value.population}
  63. </div>`;
  64. }
  65. if (result.length > 0) {
  66. divLink.style.display = 'block'
  67. } else {
  68. divLink.style.display = 'none';
  69. }
  70. }
  71. </script>
  72. </head>
  73. <body>
  74. <div class="container col-lg-5">
  75. <div class="title">
  76. <h2>Rechercher une ville</h2>
  77. </div>
  78.  
  79. <div class="form-code">
  80. <div class="form-group">
  81. <label for="code">Entrez une ville:</label>
  82. <input type="text" name="code" class="form-control" id="code" onkeyup="getCommunes(event)" />
  83. </div>
  84. </div>
  85.  
  86. <div class="result" id="result"></div>
  87. <div class="link" id="link">
  88. <a href="#" onclick="getResult()">Plus de resultats</a>
  89. </div>
  90. </div>
  91. </body>
  92. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement