Advertisement
Carmine_Annunziata

validazioneForm

May 27th, 2022
905
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function procediInserimento() {
  2.  
  3.     var varid = document.getElementById("inputID").value;
  4.     var varNome = document.getElementById("inputNome").value;
  5.     var varCognome = document.getElementById("inputCognome").value;
  6.     var varData = document.getElementById("inputDataNascita").value;
  7.     var dati = [];
  8.     var check = true;
  9.  
  10.     if(varNome.trim().length === 0){
  11.         alert("Campo nome non riempito");
  12.     }
  13.     else if(varCognome.trim().length === 0){
  14.         alert("Campo cognome non riempito");
  15.     }
  16.     else if(varData.trim().length === 0){
  17.         alert("Campo data non riempito");
  18.     }
  19.     else{
  20.  
  21.         for(int i = 0; i < arrayPersone.lenght; i++){
  22.             if(arrayPersone[i][0] == varId){
  23.                 check = false;
  24.             }
  25.         }
  26.  
  27.         if(check){
  28.             dati = [varid,varNome,varCognome,varData];
  29.             var persona = "<tr>";
  30.             persona += "<td>" + varid +    "</td>";
  31.             persona += "<td>" + varNome +    "</td>";
  32.             persona += "<td>" + varCognome + "</td>";
  33.             persona += "<td>" + varData +    "</td>";
  34.             persona += "</tr>";
  35.                  
  36.             elencoPersone += persona;
  37.             arrayPersone.push(dati);
  38.             document.getElementById("contenuto_tabella").innerHTML = elencoPersone;
  39.         }
  40.        
  41.     }
  42.  
  43. }
  44.  
  45. var elencoPersone = "";
  46. var arrayPersone = [];
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement