[Javasript + HTML] come creare textbox in tr specifica

max85646805

Nuovo Utente
8 Giu 2016
1
0
1
33
Salve a tutti! Ho un codice in javascript che duplica la prima riga di una tabella insieme ai suoi elementi. Tra questi elementi c'è una selectbox con diverse opzioni. Io vorrei che quando viene scelta un opzione venga creata una textbox nella stessa riga dove è stata scelta quell' opzione. Il codice per duplicare la riga è questo:
---------------JAVASCRIPT------------------------------
Codice:
function addRow(tableID) {
   var table = document.getElementById(tableID);
   var rowCount = table.rows.length;
   
   
   if(rowCount < 20){               // limit the user from creating fields more than your limits
     var row = table.insertRow(rowCount);
     var colCount = table.rows[0].cells.length;
     for(var i=0; i<colCount; i++) {
       var newcell = row.insertCell(i);
       newcell.innerHTML = table.rows[0].cells[i].innerHTML;
     }
   }else{
      alert("Si possono inserire massimo 20 righe!");
         
   }
   


   


   
}

function deleteRow(tableID) {
   var table = document.getElementById(tableID);
   var rowCount = table.rows.length;
   for(var i=0; i<rowCount; i++) {
     var row = table.rows[i];
     var chkbox = row.cells[0].childNodes[0];
     if(null != chkbox && true == chkbox.checked) {
       if(rowCount <= 1) {    // limit the user from removing all the fields
         alert("Non si possono cancellare tutte le righe!");
         break;
       }
       table.deleteRow(i);
       rowCount--;
       i--;
     }
   }
}

-----------------------------HTML------------------------------
Codice:
<table id="dataTable" class="table">
<tbody>
  <tr>
  <td>
  <input class="flat" type="checkbox" required="required" name="chk[]" checked="checked" />
  </td>
  <td>
     <select name="scelta[]"  required="required">
  <option>Opzione1</option>
  <option>Opzione2</option>
  <option>Opzione3</option>
  </select>
  </td>
  </tr>
</tbody>
</table>

<input type="button" value="Aggiungi Riga" onClick="addRow('dataTable')" />
<input type="button" value="Rimuovi Riga" onClick="deleteRow('dataTable')"  />
 
Discussioni simili
Autore Titolo Forum Risposte Data
S [javasript,jquery]dissolvenza d'immagini in entrata! Javascript 1
S Includere una pagina con JavaSript Javascript 14
G Pagina html in stringa PHP 2
E Sostituzione Elemento Html PHP 3
G Elementi HTML HTML e CSS 1
K Visualizzare del html responsive in una Webview Sviluppo app per Android 0
T Domanda valutazione html LinkedIn 2022 pt3 HTML e CSS 7
T Domanda valutazione html LinkedIn 2023 pt2 HTML e CSS 15
T Domanda valutazione html LinkedIn 2023 pt1 HTML e CSS 1
MarcoGrazia Salvataggio HTML in database PHP 2
K posizionare variabile da pagina html all'iframe. Javascript 1
peppe0703 Come Estrarre dati da db wordpress e richiamarli in html esterno HTML e CSS 0
L problema collegamento file css con html HTML e CSS 1
D Informazioni da XAMPP su HTML PHP 0
R Immagini html HTML e CSS 2
K File audio in html, chi mi può aiutare? HTML e CSS 0
K Aiuto con file audio in html HTML e CSS 1
Antonio67 Lanciare file shell bash da html HTML e CSS 2
M Riportare in tabella HTML dati estratti con query SQL MySQL 0
G Codice html Javascript 1
M Collegamento tra form html e script php PHP 4
L Ricezione dei dati su file php da modulo html PHP 6
F Creare elementi html con javascript Javascript 3
G Appicazione HTML per inserimento dai in Database Access Microsoft HTML e CSS 0
W visualizzare solo file html e sottocartelle di una cartella PHP 1
C Dopo chiusura del tag php la stringa html va a capo PHP 1
G img html HTML e CSS 3
M Come fare un countdown in HTML? HTML e CSS 4
D Stampa a video in altra pagina html Database 3
A inserire variabile php colore in div html PHP 2
F Tv in html Offerte e Richieste di Lavoro e/o Collaborazione 1
N Script elenco file HTML HTML e CSS 5
L salvare codice html in mysql PHP 3
Cosina htaccess redirect 301 senza estensione html Web Server 6
E Errore di lettura php in html PHP 8
M HTML e PHP Offerte e Richieste di Lavoro e/o Collaborazione 3
C Form email php su pagina index.html? PHP 21
Shyson Meglio Javascript o HTML? Javascript 4
P inserimento icone social tramite html HTML e CSS 1
Z Mod_rewrite da HTML in PHP PHP 3
L Collegare un form html ad un database access Javascript 2
P HTML integrazione wordpress HTML e CSS 0
C [RISOLTO]Inserimento variabile php in input html PHP 20
L Eliminare estensione .html HTML e CSS 9
max1974 html in tooltip Javascript 0
C Risalire al php da html PHP 27
felino Esportare tabella HTML in PDF, quale libreria usare? Javascript 1
webmachine [PHP] [JAVASCRIPT] Form strano in HTML PHP PHP 1
L [RISOLTO] Stampa a video risultato count in html PHP 13
V Servizio design pagina web e download in self contained html file Discussioni Varie 1

Discussioni simili