Advertisement
fcamuso

Javascript Lezione 25

Mar 3rd, 2022
1,387
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <!DOCTYPE html>
  2. <html lang="it-IT">
  3. <head>
  4.   <meta charset="UTF-8">
  5.   <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.2/dist/css/bootstrap.min.css"
  6.         rel="stylesheet"
  7.   >
  8.   <style>
  9.     label {font-weight: bold; color: blue;}
  10.     #gamesPosseduti, input+button {width: 50px;}
  11.   </style>
  12.   <title>CICLI</title>
  13. </head>
  14. <body>
  15.   <div class="container">
  16.     <form id="form">
  17.  
  18.       <div class="mb-3">
  19.         <label for="cognome" class="form-label">Cognome</label>
  20.         <input type="text" class="form-control bg-info bg-opacity-25" id="cognome">      
  21.       </div>
  22.  
  23.       <div class="mb-3">
  24.         <label for="games_posseduti" class="form-label">N. games? </label>
  25.         <input type="text" class="form-control bg-info bg-opacity-25" id="gamesPosseduti">
  26.         <button type="button" id="go">GO</button>
  27.       </div>
  28.     </form>
  29.   </div>
  30.  
  31.  
  32.   <script>
  33.     //otteniamo un riferimento al bottone nel DOM
  34.     let rifBottone = document.querySelector("#go");
  35.     rifBottone.addEventListener("click", generaTextBox);
  36.  
  37.     function generaTextBox()
  38.     {
  39.       let numeroGames =
  40.         parseInt(document.querySelector("#gamesPosseduti").value);
  41.      
  42.         for (let contaTextBox=1; contaTextBox<=numeroGames; contaTextBox++)
  43.         {
  44.           let nuovoInput = document.createElement('input');
  45.           nuovoInput.classList="form-control bg-info bg-opacity-25";
  46.           form.appendChild(nuovoInput);
  47.       }  
  48.     }
  49.   </script>
  50.  
  51. </body>
  52. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement