chandra7799 commited on
Commit
6d3b08c
·
verified ·
1 Parent(s): 74b393a

Create templates/index.html

Browse files
Files changed (1) hide show
  1. templates/index.html +56 -17
templates/index.html CHANGED
@@ -4,32 +4,71 @@
4
  <meta charset="UTF-8">
5
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
  <title>Timer App</title>
7
- <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8
  </head>
9
  <body>
10
- <h1>Timer App</h1>
11
- <div>
12
- <label for="seconds">Set Timer (seconds): </label>
13
- <input type="number" id="seconds" name="seconds" min="1" max="600" required>
14
- <button id="start_button">Start Timer</button>
 
 
 
 
 
15
  </div>
16
- <div id="timer_output"></div>
17
 
18
  <script>
19
- // Start timer function
20
- $("#start_button").click(function() {
21
- let seconds = $("#seconds").val();
22
 
23
- // Send a request to start the timer
24
- $.ajax({
25
- url: "/start_timer",
26
  method: "POST",
27
- data: {seconds: seconds},
28
- success: function(response) {
29
- $("#timer_output").text(response.message);
 
 
30
  }
 
 
 
 
31
  });
32
- });
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
33
  </script>
 
34
  </body>
35
  </html>
 
4
  <meta charset="UTF-8">
5
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
  <title>Timer App</title>
7
+ <style>
8
+ body {
9
+ font-family: Arial, sans-serif;
10
+ text-align: center;
11
+ margin-top: 50px;
12
+ }
13
+ .container {
14
+ display: inline-block;
15
+ text-align: left;
16
+ }
17
+ #timer_output {
18
+ margin-top: 20px;
19
+ font-size: 20px;
20
+ font-weight: bold;
21
+ }
22
+ </style>
23
  </head>
24
  <body>
25
+
26
+ <div class="container">
27
+ <h1>Timer App</h1>
28
+
29
+ <label for="seconds">Set Timer (seconds):</label>
30
+ <input type="number" id="seconds" min="1" max="600" step="1" value="10">
31
+
32
+ <button onclick="startTimer()">Start Timer</button>
33
+
34
+ <div id="timer_output"></div>
35
  </div>
 
36
 
37
  <script>
38
+ function startTimer() {
39
+ var seconds = document.getElementById("seconds").value;
 
40
 
41
+ fetch("/start_timer", {
 
 
42
  method: "POST",
43
+ body: new URLSearchParams({
44
+ seconds: seconds
45
+ }),
46
+ headers: {
47
+ "Content-Type": "application/x-www-form-urlencoded"
48
  }
49
+ })
50
+ .then(response => response.json())
51
+ .then(data => {
52
+ console.log(data.message);
53
  });
54
+
55
+ updateTimerOutput();
56
+ }
57
+
58
+ function updateTimerOutput() {
59
+ var timerOutput = document.getElementById("timer_output");
60
+ var remaining = parseInt(document.getElementById("seconds").value);
61
+ var interval = setInterval(function() {
62
+ if (remaining > 0) {
63
+ timerOutput.innerText = remaining + " seconds remaining...";
64
+ remaining--;
65
+ } else {
66
+ timerOutput.innerText = "Time's up!";
67
+ clearInterval(interval);
68
+ }
69
+ }, 1000);
70
+ }
71
  </script>
72
+
73
  </body>
74
  </html>