Guest User

Untitled

a guest
Jul 24th, 2021
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 3.16 KB | None | 0 0
  1.  
  2. <!DOCTYPE html>
  3. <html lang="fi">
  4. <head>
  5.     <meta charset="utf-8">
  6.     <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
  7.     <title>Karkausvuodet</title>
  8.     <!-- Bootstrap CSS file -->
  9.     <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css">
  10. </head>
  11. <body class="bg-light" style="max-width: 600px; margin: auto;" onload="init();">
  12. <div class="container">
  13.     <div class="py-2 text-center">
  14.         <h1 class="h1 mb-3 font-weight-normal">Karkausvuodet</h1>
  15.         <div class="justify-content-center text-center">
  16.             <form>
  17.                 <div class="form-group row">
  18.                     <label class="col-sm-2 col-form-label" for="fromYear">Vuodesta</label>
  19.                     <div class="col-sm-4">
  20.                         <input class="form-control text-center" type="number" min="0" max="9999" id="fromYear">
  21.                     </div>
  22.                         <label class="col-sm-2 col-form-label" for="toYear">Vuoteen</label>
  23.                     <div class="col-sm-4">
  24.                         <input class="form-control text-center" type="number" min="0" max="9999" id="toYear">
  25.                     </div>
  26.                 </div>
  27.             </form>
  28.         </div>
  29.         <div class="row">
  30.             <div class="col-12">
  31.                 <button type="button" onclick="getLeapYears()" class="btn btn-primary btn-block">Hae karkausvuodet</button>
  32.             </div>
  33.         </div>
  34.         <hr />
  35.         <div class="form-outline text-left">
  36.             <label class="form-label" for="leapYears">Karkausvuodet</label>
  37.             <textarea wrap="hard" class="form-control" id="leapYears" rows="10"></textarea>
  38.         </div>
  39.     </div>
  40. </div>
  41. <!-- JS files: jQuery first, then Bootstrap JS -->
  42. <script src="https://code.jquery.com/jquery-3.5.1.min.js"></script>
  43. <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script>
  44. <script>
  45. const HOST = "http://192.168.250.99:3333";
  46. const PATH = "karkausvuodet";
  47.  
  48. let from = "1901";
  49. let to = "2000";
  50.  
  51. const getLeapYears = () => {
  52.     from = document.getElementById("fromYear").value;
  53.     to = document.getElementById("toYear").value;
  54.     const URL = HOST+'/'+PATH+'/'+from+'/'+to;
  55.     fetch(URL)
  56.     .then(response => response.json())
  57.     .then(json => {
  58.         let leapYears = "";
  59.         if (json.karkausvuodet.length == 1) {
  60.             leapYears = json.karkausvuodet[0];
  61.         } else {
  62.             for (let i in json.karkausvuodet) {
  63.                 leapYears += json.karkausvuodet[i];
  64.                 if (i < json.karkausvuodet.length - 2) {
  65.                    leapYears += ", ";
  66.                }
  67.                if (i == json.karkausvuodet.length - 2) {
  68.                    leapYears += " ja ";
  69.                }
  70.  
  71.            }
  72.        }
  73.        document.getElementById("leapYears").value = leapYears;
  74.    })
  75.    .catch(err => console.log('Request Failed', err));
  76. }
  77.  
  78. const init = () => {
  79.     document.getElementById("fromYear").value = from;
  80.     document.getElementById("toYear").value = to;
  81.     getLeapYears();
  82. }
  83.  
  84. </script>
  85. </body>
  86. </html>
  87.    
  88.  
Advertisement
Add Comment
Please, Sign In to add comment