Advertisement
Guest User

Untitled

a guest
Sep 15th, 2019
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 5 4.24 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3.  
  4. <head>
  5.     <style>
  6.         form {
  7.             width: 40%;
  8.  
  9.             margin-left: 1.3em;
  10.             border: 1px solid blue;
  11.             border-radius: 10px;
  12.             padding: 2em;
  13.  
  14.             background-color: rgba(133, 199, 201, 0.12);
  15.         }
  16.  
  17.         table {
  18.             border-collapse: collapse;
  19.             width: 100%;
  20.         }
  21.  
  22.         th,
  23.         td {
  24.             text-align: left;
  25.             padding: 10px;
  26.         }
  27.  
  28.         tr:nth-child(even) {
  29.             background-color: #f2f2f2
  30.         }
  31.  
  32.         th {
  33.             background-color: blue;
  34.             color: white;
  35.         }
  36.     </style>
  37.     <script type="text/javascript" language="JavaScript">
  38.         function SubmitForm() {
  39.             var formData = readFormData();
  40.             var tabla = document.getElementById("ListaDeInstrumentos");
  41.             var buscar = doSearch();
  42.             if (formData["ID"] != "" && buscar === false) {
  43.                var NewRow = tabla.insertRow();
  44.                 cell1 = NewRow.insertCell(0);
  45.                 cell1.appendChild(document.createTextNode(formData["ID"]));
  46.                 cell2 = NewRow.insertCell(1);
  47.                 cell2.appendChild(document.createTextNode(formData["Observaciones"]));
  48.                 cell3 = NewRow.insertCell(2);
  49.                 cell3.appendChild(document.createTextNode(formData["Tipo"]));
  50.                 // si uso el form data no funciona :(  
  51.                 document.getElementById("ID").value = "";
  52.                 document.getElementById("Observaciones").value = "";
  53.                 document.getElementById("Tipo").value = "";
  54.             }
  55.         }
  56.         function readFormData() {
  57.             var formData = {};
  58.             formData["ID"] = document.getElementById("ID").value;
  59.             formData["Observaciones"] = document.getElementById("Observaciones").value;
  60.             formData["Tipo"] = document.getElementById("Tipo").value;
  61.             return formData;
  62.         }
  63.         function doSearch() {
  64.             var tabla = document.getElementById("ListaDeInstrumentos");
  65.             const search = document.getElementById("ID");
  66.             let found = false;
  67.             if (tabla.rows[1] !== undefined) {
  68.                 const cellsOfRow = tabla.rows[1].getElementsByTagName('td');
  69.  
  70.                 for (let j = 0; j < cellsOfRow.length && !found; j++) {
  71.                    const compareWith = cellsOfRow[j].innerHTML.toLowerCase();
  72.                    if (search = compareWith) {
  73.                        found = true;
  74.                    }
  75.                }
  76.            }
  77.            return found;
  78.        }
  79.    </script>
  80.     <title>
  81.         Trabajo Proyecto
  82.     </title>
  83. </head>
  84.  
  85. <body>
  86.  
  87.     <table>
  88.         <tr>
  89.             <td>
  90.                 <form onsubmit="event.preventDefault(); SubmitForm();" autocomplete="off">
  91.                     <div>
  92.                         <label>ID</label>
  93.                         <input type="number" name="ID" id="ID">
  94.                     </div>
  95.                     <div>
  96.                         <label>Tipos</label>
  97.                         <select class="form-control" id="Tipo">
  98.                             <option>Piano</option>
  99.                             <option>Violín.</option>
  100.                             <option>violonchelo</option>
  101.                             <option>guitarra</option>
  102.                         </select>
  103.                     </div>
  104.                     <div>
  105.                         <label>Observaciones</label>
  106.                         <input type="text" maxlength="255" name="Observaciones" id="Observaciones">
  107.                     </div>
  108.                     <div>
  109.                         <input type="Submit" value="Submit">
  110.                     </div>
  111.                 </form>
  112.             </td>
  113.             <td>
  114.                 <table id="ListaDeInstrumentos">
  115.                     <thead>
  116.                         <tr>
  117.                             <th id="th_id">ID</th>
  118.                             <th>Tipo</th>
  119.                             <th>Observaciones</th>
  120.                         </tr>
  121.                     </thead>
  122.                     <tbody>
  123.  
  124.                     </tbody>
  125.                 </table>
  126.             </td>
  127.         </tr>
  128.     </table>
  129. </body>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement