Guest User

Untitled

a guest
Jan 18th, 2019
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.54 KB | None | 0 0
  1. function disegnatabelleIngr() {
  2. ...
  3.  
  4. for (var i = 0; i < Math.max(arrayIngrOK.length, arrayIngrKO.length); i++) {
  5. //tabOK is the id of an html table that i have to build dinamically
  6. rok = tabOK.append("tr");
  7.  
  8.  
  9. rok.append("td");
  10. //in arrayIngrOK[i] there is a name of a ingredient that the user can insert with the input text (see more).
  11. rok.append("td").text(arrayIngrOK[i]);
  12. /*whit the field Rimuovi i want to eliminate the specific element of an array. For esample, if one user have inserted 2 elements, in the table i see
  13. eggs Rimuovi....
  14. chicken Rimuovi....
  15. pepper Rimuovi....
  16. milk Rimuovi....
  17. if i click on the text Rimuovi near the name "pepper" i want to remove the element pepper, but with this code the element that will be eliminated is always the last inserted, so, in this case, will be the element milk.*/
  18.  
  19. rok.append("td")..text("Rimuovi...").on("click", function(){
  20. arrayIngrOK.splice(i-1,1);
  21. disegnatabelleIngr();
  22. });
  23.  
  24.  
  25. rok = tabOK.append("tr");
  26. rok.append("td").append("img").attr("src", "imm/happy.png");
  27. rok.append("td").append("input").attr("type","text").attr("id", "inputOK");
  28. rok.append("td").text("Aggiungi...").on("click", function() {
  29. if(document.getElementById("inputOK").value != "" && document.getElementById("inputOK").value != null)
  30. AggiungiIngrOK();
  31. });
  32.  
  33.  
  34.  
  35. function AggiungiIngrOK(){
  36. arrayIngrOK[arrayIngrOK.length]=document.getElementById("inputOK").value;
  37. disegnatabelleIngr();
  38. }
Add Comment
Please, Sign In to add comment