Ir para conteúdo

POWERED BY:

Arquivado

Este tópico foi arquivado e está fechado para novas respostas.

lefestaf

mais uma probleminha com dom!!!

Recommended Posts

galera!!! ola, sou eu de novo!! a gora eu estou precisando fazer o seguinte:

 

var e	= document.getElementById('tbody');	var tr	= document.createElement('tr');	tr.setAttribute("id","tr_"+cont);		var a	= document.createElement('a');	a.setAttribute("onclick",e.removeChild('tr_'+cont));

eu queria que dentro do setAttribute ultilizar o removeChild, mas da erro!!!

se alguem souber, agradeco!!

Compartilhar este post


Link para o post
Compartilhar em outros sites

Tente assim:a.onclick = function() {e.removeChild('tr_'+cont)};

Compartilhar este post


Link para o post
Compartilhar em outros sites

Tente assim:a.onclick = function() {e.removeChild('tr_'+cont)};

cara, valeu mas ainda ta dando erro, vou tentando, se eu achar um jeito eu posto ai, e se agleum souber, favor postar ai tbem!! hehehevaleu!

Compartilhar este post


Link para o post
Compartilhar em outros sites

Testa esse código:

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="pt-br" lang="pt-br"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <title>Tabela</title> <script type="text/javascript">	function adicionar()	{		var tabela 	= document.getElementById("tab");		var ultima 	= tabela.rows.length;		var linha 	= tabela.insertRow(ultima);				var celula 	= linha.insertCell(0);		var nodotexto 	= document.createTextNode("teste");		celula.appendChild(nodotexto);				celula 		= linha.insertCell(1);		nodotexto 	= document.createTextNode("teste");		celula.appendChild(nodotexto);				celula 		= linha.insertCell(2);		nodotexto 	= document.createTextNode("teste");		celula.className = 'tabela-coluna2';		celula.appendChild(nodotexto);				celula 		= linha.insertCell(3);				var el;		el = document.createElement('a');		el.setAttribute('href','java script: void(0)');		el.setAttribute('title','Excluir');		el.setAttribute('name','excluir');		el.setAttribute('id','excluir');		el.onclick	= function()		{			tabela.deleteRow(ultima);		};		texto 		= document.createTextNode("Excluir");		el.appendChild(texto);		celula.appendChild(el);	}</script></head> <body><table border="1" width="200px" id="tab"></table><input type="button" value="Adicionar" onclick="adicionar();" /></body> </html>

Compartilhar este post


Link para o post
Compartilhar em outros sites

cara, com base no codigo que v c fez, eu dei uma mudada no meu, ai vai ele inteiro e ja modificado:

 

var cont = 0;function add() {	cont++;		var i	= document.regPedido.produtos.selectedIndex;	var c1	= document.regPedido.produtos.options[i].text;	var c2	= document.getElementById('quantidade').value;	var c3	= document.getElementById('prcUnit').innerHTML;	var c4	= document.getElementById('prcTotal').innerHTML;	var j	= document.regPedido.locentrega.selectedIndex;	var c5	= document.regPedido.locentrega.options[j].text;		var w	= document.getElementById('ContUSUARIO');	var e	= document.getElementById('tbody');	var tr	= document.createElement('tr');	var td1	= document.createElement('td');	var td2	= document.createElement('td');	var td3	= document.createElement('td');	var td4	= document.createElement('td');	var td5	= document.createElement('td');	var td6	= document.createElement('td');	tr.setAttribute("id","tr_"+cont);		var a	= document.createElement('a');	a.onclick = function() {w.deleteRow('tr_'+cont);}	a.setAttribute("href","#");	a.setAttribute("title","Excluir este pedido");		var img	= document.createElement('img');	img.setAttribute("src","Cliente/estrutura/Imagens/BTNdelete.gif");	img.setAttribute("id","b_"+cont);		var ith1 = document.createElement('INPUT');	ith1.setAttribute("type","hidden");	ith1.setAttribute("name","ith1_"+cont);	ith1.setAttribute("id","ith1_"+cont);		var ith2 = document.createElement('INPUT');	ith2.setAttribute("type","hidden");	ith2.setAttribute("name","ith2_"+cont);	ith2.setAttribute("id","ith2_"+cont);	var ith3 = document.createElement('INPUT');	ith3.setAttribute("type","hidden");	ith3.setAttribute("name","ith3_"+cont);	ith3.setAttribute("id","ith3_"+cont);	var ith4 = document.createElement('INPUT');	ith4.setAttribute("type","hidden");	ith4.setAttribute("name","ith4_"+cont);	ith4.setAttribute("id","ith4_"+cont);		var ith5 = document.createElement('INPUT');	ith5.setAttribute("type","hidden");	ith5.setAttribute("name","ith5_"+cont);	ith5.setAttribute("id","ith5_"+cont);		//td1.setAttribute("id","td1_"+cont);	//td2.setAttribute("id","td2_"+cont);	//td3.setAttribute("id","td3_"+cont);	//td4.setAttribute("id","td4_"+cont);	//td5.setAttribute("id","td5_"+cont);		var t1	= document.createTextNode(c1);	var t2	= document.createTextNode(c2);	var t3	= document.createTextNode(c3);	var t4	= document.createTextNode(c4);	var t5	= document.createTextNode(c5);		e.appendChild(tr);	tr.appendChild(td1);	tr.appendChild(td2);	tr.appendChild(td3);	tr.appendChild(td4);	tr.appendChild(td5);	tr.appendChild(td6);	tr.appendChild(ith1);	tr.appendChild(ith2);	tr.appendChild(ith3);	tr.appendChild(ith4);	tr.appendChild(ith5);		td1.appendChild(t1);	td2.appendChild(t2);	td3.appendChild(t3);	td4.appendChild(t4);	td5.appendChild(t5);	td6.appendChild(a);	a.appendChild(img);		document.getElementById('ith1_'+cont).value = c1;	document.getElementById('ith2_'+cont).value = c2;	document.getElementById('ith3_'+cont).value = c3;	document.getElementById('ith4_'+cont).value = c4;	document.getElementById('ith5_'+cont).value = c5;}

eu es tou tentando chegar a algum lugar, mas caso você consiga algo, poste ai!!!

 

se kiser conferir: iTelecom, ai você clica em enviar (sem escrever nada nos campos), ai clica em registrar pedido, ai você muda se kiser o que vai aparecer, e clica em adicionar, ai vai ter um botao para excluir, ai você clica e ve o resultado, é sinistro!!! http://forum.imasters.com.br/public/style_emoticons/default/devil.gif

 

valeu e continuando tentando

Compartilhar este post


Link para o post
Compartilhar em outros sites

Deixei exatamente como está a tabela do seu site, agora é só formatar do jeito que você quer:

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="pt-br" lang="pt-br"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <title>Tabela</title> <script type="text/javascript">	function add()	{		var produtos 	= document.getElementById("produtos");		var locentrega 	= document.getElementById("locentrega");		var tbody 		= document.getElementById("tbody");		var linha 		= document.createElement("tr");		var celula1 	= document.createElement("td");		var celula2 	= document.createElement("td");		var celula3 	= document.createElement("td");		var celula4 	= document.createElement("td");		var celula5 	= document.createElement("td");		var celula6 	= document.createElement("td");		var nodotexto1 	= document.createTextNode(produtos.options[produtos.selectedIndex].text);		var nodotexto2 	= document.createTextNode(document.getElementById('quantidade').value);		var nodotexto3 	= document.createTextNode(document.getElementById('prcUnit').innerHTML);		var nodotexto4 	= document.createTextNode(document.getElementById('prcTotal').innerHTML);		var nodotexto5 	= document.createTextNode(locentrega.options[locentrega.selectedIndex].text);						celula1.appendChild(nodotexto1);		linha.appendChild(celula1);				celula2.appendChild(nodotexto2);		linha.appendChild(celula2);				celula3.appendChild(nodotexto3);		linha.appendChild(celula3);				celula4.appendChild(nodotexto4);		linha.appendChild(celula4);				celula5.appendChild(nodotexto5);		linha.appendChild(celula5);				var el;		el = document.createElement('a');		el.setAttribute('href','java script: void(0)');		el.setAttribute('title','Excluir');		el.setAttribute('name','excluir');		el.setAttribute('id','excluir');		el.onclick	= function()		{			tbody.removeChild(linha);		};		texto 		= document.createTextNode("Excluir");		el.appendChild(texto);		celula6.appendChild(el);		linha.appendChild(celula6);		tbody.appendChild(linha);	}</script></head> <body><table id="ContUSUARIO" cellspacing="3" border="1"><tbody id="tbody">	<tr>		<th>Produto/Serviço</th>		<th>Quantidade</th>		<th>prc Unitário</th>		<th>prc Total</th>		<th colspan="2">Local de Entrega</th>	</tr>	<tr>		<td>			<select name="produtos" id="produtos" class="field">				<option value="-1">Selecione o Serviço</option>			</select>		</td>		<td>			<input name="quantidade" id="quantidade" size="7" maxlength="5" class="field" type="text" />		</td>		<td id="prcUnit" align="center"></td>		<td id="prcTotal" align="center"></td>		<td colspan="2">			<select id="locentrega" name="locentrega" class="field">				<option value="-1">Selecione o Endereço de Entrega</option>			</select>		</td>	</tr>	<tr>		<td colspan="6" align="center">			<a href="#" onclick="add();">Adicionar</a>		</td>	</tr>	<tr id="result">		<th>Produto/Serviço</th>		<th>Quantidade</th>		<th>prc Unitário</th>		<th>prc Total</th>		<th colspan="2">Local de Entrega</th>	</tr></tbody></table></body> </html>

Compartilhar este post


Link para o post
Compartilhar em outros sites

cara, funcionou, mas quando eu vou colocar os campos textos, para depois puxar com o php da erro, aparece assim:

Erro: document.getElementById("ith1_" + cont) has no propertiesArquivo-fonte: http://localhost/site/controle/basico.jsLinha: 262

ta ai o codigo modificado
var cont = 0;function add() {		cont++;		var produtos	= document.getElementById("produtos");	var locentrega	= document.getElementById("locentrega");	var tbody		= document.getElementById("tbody");	var tr			= document.createElement("tr");	var cel1		= document.createElement("td");	var cel2		= document.createElement("td");	var cel3		= document.createElement("td");	var cel4		= document.createElement("td");	var cel5		= document.createElement("td");	var cel6		= document.createElement("td");	var notext1	 = document.createTextNode(produtos.options[produtos.selectedIndex].text);	var notext2	 = document.createTextNode(document.getElementById('quantidade').value);	var notext3	 = document.createTextNode(document.getElementById('prcUnit').innerHTML);	var notext4	 = document.createTextNode(document.getElementById('prcTotal').innerHTML);	var notext5	 = document.createTextNode(locentrega.options[locentrega.selectedIndex].text);	var ith1 = document.createElement('INPUT');	ith1.setAttribute("type","hidden");	ith1.setAttribute("name","ith1_"+cont);	ith1.setAttribute("id","ith1_"+cont);		var ith2 = document.createElement('INPUT');	ith2.setAttribute("type","hidden");	ith2.setAttribute("name","ith2_"+cont);	ith2.setAttribute("id","ith2_"+cont);	var ith3 = document.createElement('INPUT');	ith3.setAttribute("type","hidden");	ith3.setAttribute("name","ith3_"+cont);	ith3.setAttribute("id","ith3_"+cont);	var ith4 = document.createElement('INPUT');	ith4.setAttribute("type","hidden");	ith4.setAttribute("name","ith4_"+cont);	ith4.setAttribute("id","ith4_"+cont);		var ith5 = document.createElement('INPUT');	ith5.setAttribute("type","hidden");	ith5.setAttribute("name","ith5_"+cont);	ith5.setAttribute("id","ith5_"+cont);	cel1.appendChild(notext1);	tr.appendChild(cel1);	cel2.appendChild(notext2);	tr.appendChild(cel2);			cel3.appendChild(notext3);	tr.appendChild(cel3);	cel4.appendChild(notext4);	tr.appendChild(cel4);	cel5.appendChild(notext5);	tr.appendChild(cel5);	var el;	el = document.createElement('a');	el.setAttribute('href','#');	el.setAttribute('title','Excluir');	el.onclick = function() {					tbody.removeChild(tr);				}	var img	= document.createElement('img');	img.setAttribute("src","Cliente/estrutura/Imagens/BTNdelete.gif");	img.setAttribute("id","b_"+cont);		el.appendChild(img);	cel6.appendChild(el);		tr.appendChild(ith1);	tr.appendChild(ith2);	tr.appendChild(ith3);	tr.appendChild(ith4);	tr.appendChild(ith5);		document.getElementById('ith1_'+cont).value = notext1;	document.getElementById('ith2_'+cont).value = notext2;	document.getElementById('ith3_'+cont).value = notext3;	document.getElementById('ith4_'+cont).value = notext4;	document.getElementById('ith5_'+cont).value = notext5;		tr.appendChild(cel6);	tbody.appendChild(tr);}
desde ja agradeco!

Compartilhar este post


Link para o post
Compartilhar em outros sites

ae galera, eu achei o problema, agora o codigo ta funcionando [tanto no ie quanto no ff], bom quem quiser ele ta ai:

 

var cont = 0;function add() {		cont++;// contador para definir os ids dos elementos		/* crio as variaveis  e ja defino os valores */		var produtos	= document.getElementById("produtos");	var locentrega	= document.getElementById("locentrega");	var tbody		= document.getElementById("tbody");	var tr			= document.createElement("tr");	var cel1		= document.createElement("td");	var cel2		= document.createElement("td");	var cel3		= document.createElement("td");	var cel4		= document.createElement("td");	var cel5		= document.createElement("td");	var cel6		= document.createElement("td");		var i	= document.regPedido.produtos.selectedIndex;	var c1	= document.regPedido.produtos.options[i].text;	var c2	= document.getElementById('quantidade').value;	var c3	= document.getElementById('prcUnit').innerHTML;	var c4	= document.getElementById('prcTotal').innerHTML;	var j	= document.regPedido.locentrega.selectedIndex;	var c5	= document.regPedido.locentrega.options[j].text;		/* defino um id para as linhas [acho que assim fica melhor para administrar] */	tr.setAttribute("id","tr_"+cont);	/* crio os input[hidden] para gravar os dados e depois serem enviados via POST/GET */	var ith1 = document.createElement('input');	ith1.setAttribute("type","hidden");	ith1.setAttribute("name","ith1_"+cont);	ith1.setAttribute("id","ith1_"+cont);		var ith2 = document.createElement('input');	ith2.setAttribute("type","hidden");	ith2.setAttribute("name","ith2_"+cont);	ith2.setAttribute("id","ith2_"+cont);	var ith3 = document.createElement('input');	ith3.setAttribute("type","hidden");	ith3.setAttribute("name","ith3_"+cont);	ith3.setAttribute("id","ith3_"+cont);	var ith4 = document.createElement('input');	ith4.setAttribute("type","hidden");	ith4.setAttribute("name","ith4_"+cont);	ith4.setAttribute("id","ith4_"+cont);		var ith5 = document.createElement('input');	ith5.setAttribute("type","hidden");	ith5.setAttribute("name","ith5_"+cont);	ith5.setAttribute("id","ith5_"+cont);	/* crio o link que vai conter a imagem para deletar a linha selecionada */	var el;	el = document.createElement('a');	el.setAttribute('href','#');	el.setAttribute('title','Excluir');	el.setAttribute('id','link_'+cont);	el.onclick = function() {					tbody.removeChild(tr);					}	/* pego a imagem para o link */	var img	= document.createElement('img');	img.setAttribute("src","Cliente/estrutura/Imagens/BTNdelete.gif");	img.setAttribute("id","b_"+cont);		/* transformo todos os conteudos  das variaveis Cx em texto [se eu ñ fizer isso da erro, pelo menos aqui deu] */		var t1	= document.createTextNode(c1);	var t2	= document.createTextNode(c2);	var t3	= document.createTextNode(c3);	var t4	= document.createTextNode(c4);	var t5	= document.createTextNode(c5);	/* agora incluo os elementosna tabela*/	// incluo tr no tbody	tbody.appendChild(tr);	// imagem no link	el.appendChild(img);	//link na cel  6 (coluna 6)	cel6.appendChild(el);	//incluos as celulas nas llinhas	tr.appendChild(cel1);	tr.appendChild(cel2);	tr.appendChild(cel3);	tr.appendChild(cel4);	tr.appendChild(cel5);	tr.appendChild(cel6);	/* incluos os campos text[hidden] na linha [ñ precisa ter um lugar exato, eu pensei da seguinte forma: o usuario naum vai ver, e o importante é ele receber os dados para mim poder puxar via POST/GET]*/	tr.appendChild(ith1);	tr.appendChild(ith2);	tr.appendChild(ith3);	tr.appendChild(ith4);	tr.appendChild(ith5);	// incluos os textos[tx] nas suas repectivas celulas[coluna]		cel1.appendChild(t1);	cel2.appendChild(t2);	cel3.appendChild(t3);	cel4.appendChild(t4);	cel5.appendChild(t5);	// incluo os valores de Cx nos respectivos campos text[hidden]	document.getElementById('ith1_'+cont).value = c1;	document.getElementById('ith2_'+cont).value = c2;	document.getElementById('ith3_'+cont).value = c3;	document.getElementById('ith4_'+cont).value = c4;	document.getElementById('ith5_'+cont).value = c5;}

qualquer duvida postem ai, e naum deixem de colocar meu nome nos creditos!! http://forum.imasters.com.br/public/style_emoticons/default/thumbsup.gif

e quem quiser conferir rodando: iTelecom

ai é só clicar em : entrar/registrar pedido/ ai em adicionar

depois podem comecar a excluir, e vão ver como ele funciona!!!

 

qualquer coisa é só postar ae!!

 

valeu!!

 

obs: pode colocar resolvido no titulo do topico por favor!!!!

Compartilhar este post


Link para o post
Compartilhar em outros sites

×

Informação importante

Ao usar o fórum, você concorda com nossos Termos e condições.