Usamos cookies para medir audiência e melhorar sua experiência. Você pode aceitar ou recusar a qualquer momento. Veja sobre o iMasters.
Boa tarde amigos,
Estou fazendo um formulário simples, onde preciso cadastrar tres campos text: código, descrição e valor.
Estes campos estão dentro de uma table, para melhor organização.
Só que eu preciso viabilizar o cadastro de 'n' códigos, descrições e valores; de acordo com a necessidade do usuário, claro.
Eu pensei em um botão (button) onde o usuário possa clicar para aparecer uma nova linha na tabela, onde contenha novos campos (vazios) de código, descrição e valor.
E tantas vezes que o usuário clicar, será a quantidade de linhas novas inseridas nesta tabela.
Alguém tem algo semi-pronto ou alguma idéia de como fazer?
Obrigado
Fico muito agradecido com quem visitou a dúvida postada.
Descobri como fazer funcionar esse código em meu projeto. O que eu não estou conseguindo é resgatar um valor numérico, como por exemplo "13,40", através de um $_POST.
O código em Javascript é o seguinte:
-------
<script language="javascript" type="text/javascript">
function addRowToTable()
{
var tbl = document.getElementById('tblSample');
var lastRow = tbl.rows.length;
// if there's no header row in the table, then iteration = lastRow + 1
var iteration = lastRow;
var row = tbl.insertRow(lastRow);
// left cell
var cellLeft = row.insertCell(0);
var textNode = document.createTextNode(iteration);
cellLeft.appendChild(textNode);
// right cell
var cellRight = row.insertCell(1);
var el = document.createElement('input');
el.setAttribute('type', 'text');
el.setAttribute('name', 'tcod[]' + iteration);
el.setAttribute('id', 'txtRow' + iteration);
el.setAttribute('size', '3');
el.onkeypress = keyPressTest;
cellRight.appendChild(el);
var cellRight = row.insertCell(1);
var el = document.createElement('input');
el.setAttribute('type', 'text');
el.setAttribute('name', 'thistorico[]' + iteration);
el.setAttribute('id', 'txtRow' + iteration);
el.setAttribute('size', '90');
el.onkeypress = keyPressTest;
cellRight.appendChild(el);
var cellRight = row.insertCell(1);
var el = document.createElement('input');
el.setAttribute('type', 'text');
el.setAttribute('name', 'tvalor[]' + iteration);
el.setAttribute('id', 'txtRow' + iteration);
el.setAttribute('size', '7');
el.onkeypress = keyPressTest;
cellRight.appendChild(el);
}
function keyPressTest(e, obj)var validateChkb = document.getElementById('chkValidateOnKeyPress');
if (validateChkb.checked) {
var displayObj = document.getElementById('spanOutput');
var key;
if(window.event) {
key = window.event.keyCode;
}
else if(e.which) {
key = e.which;
}
var objId;
if (obj != null) {
objId = obj.id;objId = this.id;
}
displayObj.innerHTML = objId + ' : ' + String.fromCharCode(key);
}
}
function removeRowFromTable()var tbl = document.getElementById('tblSample');
var lastRow = tbl.rows.length;
if (lastRow > 2)
tbl.deleteRow(lastRow - 1);
}
function openInNewWindow(frm)var aWindow = window.open('', 'TableAddRowNewWindow',
'scrollbars=yes,menubar=yes,resizable=yes,toolbar=no,width=400,height=400');
// set the target to the blank window
frm.target = 'TableAddRowNewWindow';
// submit
frm.submit();
}
</script>Repararam que o código gera tres campos text, um dele é o campo que recebe o valor.
ao invés de me retornar os '13,80' ou '13.80', ele me retorna '14'.
Agradeço a atenção.
Diogo.
Amigos, encontrei uma dica aqui no fórum que parece ser boa, estou tentando adaptar ao meu código, que ficou assim:
nota: O código precisa apenas inserir outras linhas abaixo da primeiro que já existe. E precisa ser um array, assim como a primeira está definida, pois preciso resgatar todos estes campos depois.
OBRIGADO!
<!-- body { --> { // if there's no header row in the table, then iteration = lastRow + 1// left cell
// right cell
{
} else {
{
{
// open a blank window
// set the target to the blank window
frm.target = 'TableAddRowNewWindow';
// submit
<?
<?
if ($_POST)
{
if ($rs=mssql_fetch_array($rsa))
{
<?
}
else
{
}
<?
}