Advertisement
Guest User

02 Bus Schedule

a guest
Nov 23rd, 2017
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.62 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>Bus Schedule</title>
  6. <style>
  7. #schedule { text-align: center; width: 400px; }
  8. input { width: 120px; }
  9. #info { background-color:aquamarine; border:1px solid black; margin:0.25em; }
  10. .info { font-size: 1.5em; padding: 0.25em; }
  11. </style>
  12.  
  13.  
  14. </head>
  15. <body>
  16. <div id="schedule">
  17. <div id="info"><span class="info">Not Connected</span></div>
  18. <div id="controls">
  19. <input id="depart" value="Depart" type="button" onclick="changeStatus('depart')">
  20. <input id="arrive" value="Arrive" type="button" onclick="changeStatus('arrive')" disabled="true">
  21. </div>
  22. </div>
  23. <script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
  24. <script>
  25. let nextBusId = 'depot';
  26. function changeStatus(type) {
  27. $.ajax('https://judgetests.firebaseio.com/schedule/'+nextBusId+'.json', {
  28. method: 'GET',
  29. success: function (response) {
  30. if (type === 'depart') {
  31. $('span.info').text('Next stop ' + response.name);
  32. $('#depart').attribute('disabled', true);
  33. $('#arrive').attribute('disabled', false);
  34. }
  35. else if (type === 'arrive'){
  36. $('span.info').text('Arriving at ' + response.name);
  37. $('#arrive').attribute('disabled', true);
  38. $('#depart').attribute('disabled', false);
  39.  
  40. nextBusId = response.next;
  41. }
  42.  
  43.  
  44. }
  45. });
  46. }
  47. </script>
  48. </body>
  49. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement