[Javascript] indirizzare stringa come nome input text

Luca2111

Nuovo Utente
13 Mar 2017
1
0
1
40
Ciao,

ho creato delle input text dinamiche inserite in una tabella con due cicli for.
Ho nominato queste input nel modo id+i+riga e per controllo ho affidato il nome della inpt con il suo valore. Ora nella funzione calcola, devo moltiplicare il valore di id01 per id11 per id21 per id31 e scriverlo in id51. Questo valore verra' poi moltiplicato per un valore fisso a seconda della scelta della casella select e scritto in id61. Questo per ogni riga. Allego foto per chiarimenti.

Il codice è questo:
HTML:
<script type="text/javascript">

var riga=0;
/* funzione Add */

function Add(id_table)
   {
   riga=riga+1;
   var table = document.getElementById(id_table);
   var tbody = table.getElementsByTagName('tbody')[0];
   var tr = document.createElement("tr");
   for(var i=0; i<7; i++)
       {
       if(i!=4)
           {
           var td = document.createElement('td');
           var tx = document.createElement("input");
           if(i>4)
               {
               tx.type="text";
               tx.readOnly="true";
               tx.name="id"+i+riga;
               tx.value=tx.name;
               }
           else  
               {
               tx.type="text";
               tx.value="0";
               tx.name="id"+i+riga;
               tx.value=tx.name;
               }
           td.appendChild(tx);
           tr.appendChild(td);
           }
       else
           {  
               td = document.createElement('td');
               tx = document.createElement("select");
               tx.options[tx.length] = new Option('abete kvh');
               tx.options[tx.length] = new Option('abete lamellare');
               td.appendChild(tx);
               tr.appendChild(td);
           }  
       }
   tbody.appendChild(tr);
   }


/* funzione calcola */

function calcola()
{
   selIdx = document.forms[0].materiale.selectedIndex;
   switch (selIdx)
       {   case 0:       { price=325;
                     break;
                   }
           case 1:       { price=396;
                   break;
                   }
       }
metricubi=form1.numero.value*(form1.larg.value/100)*(form1.alt.value/100)*(form1.lung.value/100);
form1.mc.value=eval(metricubi);

for(var k=1;k<riga+1;k++)
   {   for(var j=0;j<4;j++)
           {   var nome="id"+j+k;
               alert(nome);  
           }
   }
}
</script>
C'è qualcuno che puo' aiutarmi
Grazie

Luca
 

Allegati

  • Immagine.jpg
    Immagine.jpg
    25,5 KB · Visite: 428
Ultima modifica di un moderatore:
Ciao, a questora avrai gia risolto, cmq non hai dato un name alla select e tutte le operazioni della funzione calcola devono essere eggettuate allìinterno del ciclo.
 

Discussioni simili