
Enviado em 17/11/2015 - 12:34h
É o seguinte galera tenho uma tabela dinâmica em javaScript onde inclui uma linha com alguns dados preenchidos pelo usuário, no método de adicionar a linha coloquei um array passando também os campos que estou mandando para a tabela mas quando vou ver os valores do array não aparece nada como se estivesse vazio segue o código.<html>
<head>
<title> pedido </title>
<script LANGUAGE="JavaScript">
totals =0;
//Função que adiciona linha na tabela
function adiciona(){
//Array para pegar o valores mandados para a tabela
var itens = [];
var prod = document.getElementById('cprod').value;
var qtd = document.getElementById('cquant').value;
itens.push(prod, qtd);
totals++
tbl = document.getElementById("tabelaBanco");
var novaLinha = tbl.insertRow(-1);
var novaCelula;
if(totals%2==0) cl = "#FFFFFF";
else cl = "##FFFFFF";
novaCelula = novaLinha.insertCell(0);
novaCelula.align = "left";
novaCelula.style.backgroundColor = cl;
novaCelula.innerHTML = document.getElementById('cprod').value;
totals;
novaCelula = novaLinha.insertCell(1);
novaCelula.align = "left";
novaCelula.style.backgroundColor = cl;
novaCelula.innerHTML = document.getElementById('cquant').value;
novaCelula2 = novaLinha.insertCell(2);
novaCelula.align = "left";
novaCelula.style.backgroundColor = cl;
var btnEl = document.createElement('input');
btnEl.setAttribute('type', 'button');
btnEl.setAttribute('class', 'btn');
btnEl.onclick = function () {deleteRow(this.parentNode.parentNode.rowIndex)};
btnEl.setAttribute('value', 'Delete');
novaCelula2.appendChild(btnEl);
}
function deleteRow(i){
document.getElementById('tabelaBanco').deleteRow(i)
}
//Função de teste para ver se esta pegando o array
function pedido(){
alert(itens);
}
</script>
</head>
<body>
<table>
<td> Produto: <input type="text" name="produto" id="cprod" /> </td>
<td> Quantidade: <input type="number" name="quantidade" id="cquant" /> </td>
<td> <input type='button' id='incluir' value='Incluir Produto' class="btn btn-primary" onclick='adiciona()'/> </td>
</table>
<table id='tabelaBanco' class="table table-hover" border='0' width='100%'>
<thead>
<tr style='background-color:#FBF6F7'>
<td class="produto"><strong>Produto</strong></td>
<td class="quantidade"><strong>Quantidade</strong></td>
<td><strong>Excluir</strong></td>
</tr>
</thead>
<tbody>
</tbody>
</table>
<p> <input type='button' id='confirmar' value='Confirmar Pedido' class="btn btn-primary" onclick='pedido()'/>
</body>
</html>
Fscrypt: protegendo arquivos do seu usuário sem a lentidão padrão de criptograr o disco
Faça suas próprias atualizações de pacotes/programas no Void Linux e torne-se um Contribuidor
Como rodar o Folding@home no Linux
Criando um painel de controle (Dashboard) para seu servidor com o Homepage
O Abismo entre o Código e o Chão: Saltos Tecnológicos e a Exclusão Estrutural no Brasil
Utilizando a Ferramenta xcheckrestart no Void Linux
Pisando no acelerador do Linux Mint: Kernel XanMod, zRAM e Ajustes de Swap
Como compilar kernel no Linux Mint
Abrir um arquivo URL pelo Clipper (9)
Seno, Coseno, Tangente em CLIPPER (1)
Inserir uma URL num arquvo pelo Ubuntu (CLIPPER) (0)
VMWare Player não conecta na rede nem consigo intercambiar arquivos (1)









