Visualizzazione dei risultati da 1 a 2 su 2
  1. #1
    Utente di HTML.it
    Registrato dal
    Oct 2006
    Messaggi
    213

    elimina riga da tabella

    ho questa funzione js che inserisce righe dinamicamente:
    codice:
    function AddRow(cntRow) {
    	var newcell="<input type=\"text\" name=\"riga"+"\" size=\"7\" value=\""+(tDettaglio.rows.length-1)+"\">"
    	var newcell2="<input type=\"text\" name=\"art"+"\" size=\"20\">"
    	var newcell3="<input type=\"text\" name=\"qnt"+"\" size=\"20\">"
    	var newcell4="<input type=\"text\" name=\"prezzo"+"\" size=\"20\">"
    	var newcell5="<input type=\"button\" name=\"B2"+"\" size=\"20\" value=\"Inserisci Riga\" onclick=\"AddRow()\">"
    	var newcell6="<input type=\"button\" name=\"B3"+"\" id=\""+(cntRow+1)+"\" size=\"20\" value=\"Elimina Riga\" onclick=\"DelRow()\">"			
    		
    		tDettaglio.insertRow()
    		tDettaglio.rows(tDettaglio.rows.length-1).insertCell()
    		tDettaglio.cells(tDettaglio.cells.length-1).innerHTML=newcell
    		tDettaglio.rows(tDettaglio.rows.length-1).insertCell()
    		tDettaglio.cells(tDettaglio.cells.length-1).innerHTML=newcell2
    		tDettaglio.rows(tDettaglio.rows.length-1).insertCell()
    		tDettaglio.cells(tDettaglio.cells.length-1).innerHTML=newcell3
    		tDettaglio.rows(tDettaglio.rows.length-1).insertCell()
    		tDettaglio.cells(tDettaglio.cells.length-1).innerHTML=newcell4
    		tDettaglio.rows(tDettaglio.rows.length-1).insertCell()
    		tDettaglio.cells(tDettaglio.cells.length-1).innerHTML=newcell5
    		tDettaglio.rows(tDettaglio.rows.length-1).insertCell()
    		tDettaglio.cells(tDettaglio.cells.length-1).innerHTML=newcell6
    	}
    ora il mio problema è eliminare una riga specifica al click del pulsante.ho provato con:
    [CODE]
    function DelRow() {
    tDettaglio.deleteRow(document.getElementById('B3') );
    }
    ma elimina solo l'ultima riga della tabella e non quella selezionata

  2. #2
    Utente di HTML.it
    Registrato dal
    Oct 2006
    Messaggi
    213
    risolto così:
    codice:
    	var cntRows=1;
    	function AddRow() {
    		cntRows++
    		var cell=cntRows
    		var newcell="<input type=\"text\" name=\"riga"+"\" size=\"7\" value=\""+cell+"\">"
    		var newcell2="<input type=\"text\" name=\"art"+"\" size=\"20\">"
    		var newcell3="<input type=\"text\" name=\"qnt"+"\" size=\"20\">"
    		var newcell4="<input type=\"text\" name=\"prezzo"+"\" size=\"20\">"
    		var newcell5="<input type=\"button\" name=\"B2"+"\" size=\"20\" value=\"Inserisci Riga\" onclick=\"AddRow()\">"
    		var newcell6="<input type=\"button\" name=\"B3"+"\" size=\"20\" value=\"Elimina Riga\" onclick=\"DelRow()\">"			
    		
    		tDettaglio.insertRow()
    		tDettaglio.rows(tDettaglio.rows.length-1).insertCell()
    		tDettaglio.cells(tDettaglio.cells.length-1).innerHTML=newcell
    		tDettaglio.rows(tDettaglio.rows.length-1).insertCell()
    		tDettaglio.cells(tDettaglio.cells.length-1).innerHTML=newcell2
    		tDettaglio.rows(tDettaglio.rows.length-1).insertCell()
    		tDettaglio.cells(tDettaglio.cells.length-1).innerHTML=newcell3
    		tDettaglio.rows(tDettaglio.rows.length-1).insertCell()
    		tDettaglio.cells(tDettaglio.cells.length-1).innerHTML=newcell4
    		tDettaglio.rows(tDettaglio.rows.length-1).insertCell()
    		tDettaglio.cells(tDettaglio.cells.length-1).innerHTML=newcell5
    		tDettaglio.rows(tDettaglio.rows.length-1).insertCell()
    		tDettaglio.cells(tDettaglio.cells.length-1).innerHTML=newcell6
    	}
    	function DelRow() {
    		var current = window.event.srcElement;
      		while ( (current = current.parentElement)  && current.tagName !="TR");
           		 current.parentElement.removeChild(current);
    	}
    grazie cmq

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2026 vBulletin Solutions, Inc. All rights reserved.