Advertisement
jcunews

local-db.html

Nov 15th, 2022
39
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 2.47 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <script src="https://code.jquery.com/jquery-2.1.4.js"></script>
  5.   <meta charset="utf-8">
  6.   <meta name="viewport" content"width=device-width">
  7.   <title>MDT</title>
  8. </head>
  9. <body>
  10.  
  11. <h2>DISPATCH DATABSE</h2>
  12.  
  13. <form actionq="/Dispatch">
  14.   <label for="callsign">Callsign:</label><br>
  15.   <input type="text" id="callsign" name="callsign"><br>
  16.   <label for="status">Select status:</label><br>
  17.   <select name="status" id="status">
  18.     <option value="Available">Available</option>
  19.     <option value="Busy">Busy</option>
  20.     <option value="Unavailable">Unavailable</option>
  21.     <option value="Traffic Stop">Traffic Stop</option>
  22.     <option value="Scene">Scene</option>
  23.     <option value="Radar">Radar</option>
  24.     <option value="Game Crash">Game Crash</option>
  25.   </select><br>
  26.   <label for="postal">Nearest Postal:</label><br>
  27.   <input type="text" id="postal" name="postal"><br>
  28.   <button onclick="addRow()">ADD</button>
  29. </form> <br><br>
  30.  
  31. <table border="1" id="Units">
  32.   <thead>
  33.     <tr>
  34.      <th>Callsign</th>
  35.      <th>Status</th>
  36.      <th>Location</th>
  37.     </tr>
  38.   </thead>
  39.     <tbody id="screen">
  40.   </tbody>
  41. </table>
  42.  
  43. </body>
  44.  
  45.   <script>
  46.     $( document ).ready(function(){
  47.       //load records
  48.       $('#screen').html(localStorage.getItem("data"));
  49.     });
  50.     function addRow(){
  51.       //search for any existing record first.
  52.       //note: record match is based on case-sensitive callsign name
  53.       var callsignText = $('#callsign').val().trim();
  54.       var statusText = $('#status').val().trim();
  55.       var postalText = $('#postal').val().trim();
  56.       var theRow = $('#screen tr').filter(function(index, row) {
  57.         var firstColumn = $(row).find('td:first-child');
  58.         return firstColumn.text() === callsignText;
  59.       });
  60.       if (theRow.length === 0) { //no match. add new
  61.         //note: it's recommended to populate element text content using
  62.         //      `text()` instead of `append()` or `html()` for reliable result.
  63.         $('#screen').append('<tr class = "boxType"><td></td><td></td><td></td></tr>');
  64.         theRow = $('#screen tr:last-child');
  65.         //populate the first row
  66.         theRow.find('td:nth-child(1)').text(callsignText);
  67.       }
  68.       //populate/update second and third rows
  69.       theRow.find('td:nth-child(2)').text(statusText);
  70.       theRow.find('td:nth-child(3)').text(postalText);
  71.       //save records
  72.       localStorage.setItem("data", $('#screen').html());
  73.     }
  74.   </script>
  75. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement