Advertisement
Darksoul__

Untitled

Oct 25th, 2020 (edited)
203
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 1.46 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4.     <title>Negozio Tech</title>
  5.     <script src="array.js" type="text/javascript">
  6.  
  7.         function controllaValore(){
  8.             for(i=0;i<4;i++){
  9.                 if(mioForm.qta[i].value>20||mioForm.qta[i].value<0){
  10.                     alert("Inserisci un numero compreso tra 0 e 20");
  11.                 }              
  12.             }
  13.         }
  14.  
  15.         function aggiornaTotaleSingoli(){
  16.             for(i=0;i<4;i++){
  17.                 mioForm.tot[i].value=parseInt(mioForm.qta[i].value)*costi[i];
  18.             }
  19.         }
  20.  
  21.         function aggiornaTotale(){
  22.             var totale=0;
  23.             for(i=0;i<4;i++){
  24.                 totale+=parseInt(mioForm.tot[i].value);
  25.             }
  26.         }
  27.         for(i=0;i<4;i++){
  28.             document.getElementById("qta[i]").addEventListener("change", aggiornaTotaleSingoli);
  29.             document.getElementById("qta[i]").addEventListener("change", controllaValore);
  30.             document.getElementById("qta[i]").addEventListener("change", aggiornaTotale);          
  31.         }
  32.     </script>
  33. </head>
  34. <body>
  35.     <form name="mioForm">
  36.         <table border="1" align="center">
  37.             <tr><th>Q.tà</th><th>Descrizione</th><th>Costo unitario</th><th>Totale</th></tr>
  38.             <script type="text/javascript">
  39.                 for(i=0;i<4;i++){
  40.                     document.writeln("<tr> <td><input type='text' id='qta' value='0' size='3'></td> <td>"+descrizioni[i]+"</td><td align='right'>"+costi[i]+"€</td> <td><input type='text' name='tot' value='0' readonly></td> </tr>");
  41.                 }
  42.             </script>
  43.             <tr><th colspan="3" align="Right">Totale Ordine</th><td><input type="text" value="0" name="totale" readonly></td></tr>
  44.         </table>
  45.     </form>
  46. </body>
  47. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement