Guest User

html

a guest
Dec 6th, 2019
32
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <!DOCTYPE html>
  2. <html lang="en">
  3.  
  4. <head>
  5.   <meta charset="UTF-8" />
  6.   <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  7.   <meta http-equiv="X-UA-Compatible" content="ie=edge" />
  8.   <title>Municipios de Cádiz</title>
  9.   <script>
  10.     window.onload = function () {
  11.       var x = new XMLHttpRequest();
  12.       x.onreadystatechange = function () {
  13.         if (x.readyState == 4 && x.status == 200) {
  14.          var comarcas = JSON.parse(x.responseText);
  15.           muestraComarcas(comarcas);
  16.         }
  17.       };
  18.       x.open("GET", "comarcas.php", true);
  19.       x.send();
  20.     };
  21.  
  22.     function municipios(valor) {
  23.       if (valor != -1) {
  24.         var x = new XMLHttpRequest();
  25.         x.onreadystatechange = function () {
  26.           if (this.readyState == 4 && this.status == 200) {
  27.            var municipios = JSON.parse(this.responseText);
  28.             var salida = "";
  29.             salida += `Municipio: <select id = "municipio">`;
  30.             salida += `<option value = "-1"> Seleccionar municipio </option>`;
  31.             for (var i = 0; i < municipios.length; i++) {
  32.              salida += `<option value="${municipios[i].id}">${municipios[i].nombre}</option>`;
  33.             }
  34.             salida += "</select>";
  35.             document.getElementById("municipios").innerHTML = salida;
  36.           }
  37.         };
  38.         x.open("GET", "municipios.php?comarca=" + valor, true);
  39.         x.send();
  40.       }
  41.     }
  42.  
  43.     function muestraComarcas(comarcas) {
  44.       for (var i = 0; i < comarcas.length; i++) {
  45.        document.getElementById(
  46.          "comarca"
  47.        ).innerHTML += `<option value="${comarcas[i].id}">${comarcas[i].nombre}</option>`;
  48.       }
  49.     }
  50.   </script>
  51. </head>
  52.  
  53. <body>
  54.   <h1>Provincia de Cádiz</h1>
  55.  
  56.   Comarca
  57.   <select name="comarca" id="comarca" onchange="municipios(this.value)">
  58.     <option value="-1">Seleccionar comarca</option>
  59.   </select>
  60.   <div id="municipios"></div>
  61. </body>
  62.  
  63. </html>
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×