Ir para conteúdo
Fórum Script Brasil

russoirp

Membros
  • Total de itens

    1
  • Registro em

  • Última visita

Tudo que russoirp postou

  1. Eah Galera, beleza? Estou com o sequinte problema: Tenho uma rotina que monta linhas dinamicas para uma nota fiscal (itens da nota), que clicando no "+" ele inseri uma nova linha com inputs em branco para serem preenchidos e clicando no "-" ele remove a linha. A Questão que o código funciona só no Firefox, mas no Internet Explorer não. O código segue abaixo, se alquem puder dar uma força e adaptar o código para rodar tb no I.E. , pois isso é para minha monografia e eu sei que se eu levar isso para banca assim eles vão me "fuzilar" ... hehehehe <script language="javascript" type="text/javascript"> function calculaTotal(){ var tabela = document.getElementById('list_produtos'); var row = tabela.rows.length; cont = 0; numColunas = 5; pos = 0; col = 0; t = 0; lista = ''; for(lin=0;lin<=row-1;lin++){ for(col=0;col<=numColunas;col++){ pos = (lin * 6) + cont if(col ==5){ if(document.forms[1].elements[pos-1].value == ''){ unid = 0; }else{ unid = parseInt(document.forms[1].elements[pos-1].value); } if(document.forms[1].elements[pos].value == ''){ valor = 0; }else{ valor = parseFloat(document.forms[1].elements[pos].value); } if(isNaN(unid)==false || isNaN(valor)==false){ t = (unid * valor) + t; document.getElementById('total').value = t; } } cont++ } cont = 0; } } //----------------------------------------------------------------------------// function verificaEspaco(numCol){ var tabela = document.getElementById('list_produtos'); var row = tabela.rows.length; cont = 0; numColunas = numCol; pos = 0; col = 0; total = 0; for(lin=0;lin<=row-1;lin++){ for(col=0;col<=numColunas;col++){ pos = (lin * (numCol + 1)) + cont if(document.forms[1].elements[pos].value == ''){ total++; } cont++ } cont = 0; } return total; } //--------MASCARAS--------------------------------------------------------------------// function mascara(o,f){ v_obj = o v_fun = f setTimeout('mascaraExc()',1) } function mascaraExc(){ v_obj.value = v_fun(v_obj.value) } function soNumeros(v){ return v.replace(/\D/g,'') } function telefone(v){ v=v.replace(/\D/g,'') v=v.replace(/^(\d\d)(\d)/g,'($1) $2') v=v.replace(/(\d{4})(\d)/,'$1-$2') return v } function cpf(v){ v=v.replace(/\D/g,'') v=v.replace(/(\d{3})(\d)/,'$1.$2') v=v.replace(/(\d{3})(\d)/,'$1.$2') v=v.replace(/(\d{3})(\d{1,2})$/,'$1-$2') return v } function cep(v){ v=v.replace(/\D/g,'') v=v.replace(/^(\d{5})(\d)/,'$1-$2') return v } function date(v){ v=v.replace(/\D/g,'') v=v.replace(/^(\d{2})(\d)/,'$1-$2') v=v.replace(/(\d{2})(\d)/,'$1-$2') return v } function cnpj(v){ v=v.replace(/\D/g,'') v=v.replace(/^(\d{2})(\d)/,'$1.$2') v=v.replace(/^(\d{2})\.(\d{3})(\d)/,'$1.$2.$3') v=v.replace(/\.(\d{3})(\d)/,'.$1/$2') v=v.replace(/(\d{4})(\d)/,'$1-$2') return v } function site(v){ v=v.replace(/^http:\/\/?/,'') dominio=v caminho='' if(v.indexOf('/')>-1) dominio=v.split('/')[0] caminho=v.replace(/[^\/]*/,'') dominio=dominio.replace(/[^\w\.\+-:@]/g,'') caminho=caminho.replace(/[^\w\d\+-@:\?&=%\(\)\.]/g,'') caminho=caminho.replace(/([\?&])=/,'$1') if(caminho!='')dominio=dominio.replace(/\.+$/,'') v='http://'+dominio+caminho return v } function FormataReais(fld, milSep, decSep, e) { var sep = 0; var key = ''; var i = j = 0; var len = len2 = 0; var strCheck = '0123456789'; var aux = aux2 = ''; var whichCode = (window.Event) ? e.which : e.keyCode; if (whichCode == 13 || whichCode == 08) return true; key = String.fromCharCode(whichCode); // Valor para o código da Chave if (strCheck.indexOf(key) == -1) return false; // Chave inválida len = fld.value.length; for(i = 0; i < len; i++) if ((fld.value.charAt(i) != '0') && (fld.value.charAt(i) != decSep)) break; aux = ''; for(; i < len; i++) if (strCheck.indexOf(fld.value.charAt(i))!=-1) aux += fld.value.charAt(i); aux += key; len = aux.length; if (len == 0) fld.value = ''; if (len == 1) fld.value = '0'+ decSep + '0' + aux; if (len == 2) fld.value = '0'+ decSep + aux; if (len > 2) { aux2 = ''; for (j = 0, i = len - 3; i >= 0; i--) { if (j == 3) { aux2 += milSep; j = 0; } aux2 += aux.charAt(i); j++; } fld.value = ''; len2 = aux2.length; for (i = len2 - 1; i >= 0; i--) fld.value += aux2.charAt(i); fld.value += decSep + aux.substr(len - 2, len); } return false; } //-----------------------------------------------------------------------------------------------------------// function ocultaTabela(){ if(document.getElementById('tabela').style.display == 'table'){ document.getElementById('tabela').style.display = 'none'; document.getElementById('miniminiza').value = '<'; }else if(document.getElementById('tabela').style.display == 'none'){ document.getElementById('tabela').style.display = 'table'; document.getElementById('miniminiza').value = 'v'; } } //------------------------------- Incluir Itens da Nota Fiscal ----------------------------------------------// function IncluirLinhaTabela(){ total = verificaEspaco(5); if(total == 0){ //calculaTotal(); var tabela = document.getElementById('list_produtos'); var lastRow = tabela.rows.length; var row = tabela.insertRow(lastRow); var col0 = row.insertCell(0); var nr = document.createTextNode(lastRow); col0.appendChild(nr); var col1 = row.insertCell(1); var cod = document.createElement('input'); cod.setAttribute('type', 'text' ); cod.setAttribute('name', 'cod'+lastRow); cod.setAttribute('id', 'cod'+lastRow); cod.setAttribute('size','2'); cod.setAttribute('onkeypress','mascara(this,soNumeros)'); cod.setAttribute('maxlength','6'); col1.appendChild(cod); var col2 = row.insertCell(2); var mrc = document.createElement('input'); mrc.setAttribute('type', 'text' ); mrc.setAttribute('name', 'marca'+lastRow); mrc.setAttribute('id', 'marca'+lastRow); mrc.setAttribute('size','10'); mrc.setAttribute('maxlength','80'); col2.appendChild(mrc); var col3 = row.insertCell(3); var tp = document.createElement('select'); /* <select name="selUfCid" id="selUfCid"> <?php $query = "select cd_material, ds_material from uf order by ds_material"; $cons = db_query($connect, $query); combo($connect, $selUfCid, $query, $blank="Selecionar Material"); ?> </select>*/ var opt1 = document.createElement('option'); var muito = document.createTextNode('muito'); opt1.setAttribute('value','muito'); var opt2 = document.createElement('option'); var ltr = document.createTextNode('lt'); opt2.setAttribute('value','ltr'); var opt3 = document.createElement('option'); var uni = document.createTextNode('unit'); opt3.setAttribute('value','uni'); opt1.appendChild(muito); opt2.appendChild(ltr); opt3.appendChild(uni); tp.appendChild(opt1); tp.appendChild(opt2); tp.appendChild(opt3); col3.appendChild(tp); var col4 = row.insertCell(4); var desc = document.createElement('input'); desc.setAttribute('type', 'text' ); desc.setAttribute('name', 'desc'+lastRow); desc.setAttribute('id', 'desc'+lastRow); desc.setAttribute('size','35'); desc.setAttribute('maxlength','100'); col3.appendChild(desc); var col5 = row.insertCell(5); var qtde = document.createElement('input'); qtde.setAttribute('type', 'text' ); qtde.setAttribute('name', 'qtde'+lastRow); qtde.setAttribute('id', 'qtde'+lastRow); qtde.setAttribute('onkeypress','mascara(this,soNumeros)'); qtde.setAttribute('size','1'); qtde.setAttribute('maxlength','4'); col5.appendChild(qtde); var col6 = row.insertCell(6); var qunit = document.createElement('input'); qunit.setAttribute('type', 'text' ); qunit.setAttribute('name', 'qunit'+lastRow); qunit.setAttribute('id', 'qunit' +lastRow); qunit.setAttribute('size','7'); qunit.setAttribute('onkeypress','return(FormataReais(this,\'.\',\'\.\',event))'); qunit.setAttribute('onblur','calculaTotal()'); qunit.setAttribute('maxlength','10'); col6.appendChild(qunit); var col7 = row.insertCell(7); var exclui = document.createElement('img'); exclui.setAttribute('src', '../imagens/edit_remove.png' ); exclui.setAttribute('alt', 'Remover'); exclui.setAttribute('title', 'Remover'); exclui.setAttribute('onclick','removeRowFromTable(this.parentNode.parentNode.rowIndex)'); col7.appendChild(exclui); } } function removeRowFromTable(row){ document.getElementById('list_produtos').deleteRow(row); calculaTotal(); } //-------OBJETO AJAX---------------------------------------------// function objAjax(){ try{ xmlHttp = new ActiveXObject('Microsoft.XMLHTTP'); } catch(e){ try{ xmlHttp = new ActiveXObject('Msxml2.XMLHTTP'); } catch(ex){ try{ xmlHttp = new XMLHttpRequest(); } catch(exc){ alert('Navegador sem suporte ao Ajax!'); xmlHttp = null; } } } return xmlHttp; } //----------------------------------------------------------------------------------------// function listaProdutos(){ objAjax(); var forne = document.getElementById('fornecedor').value; var nf_desc = document.getElementById('descri').value; var nr_nf = document.getElementById('nr_nf').value; var serie = document.getElementById('serie').value; var nr_rm = document.getElementById('nr_rm').value; var dt_em = document.getElementById('data').value; var tp_nf = document.getElementById('tipo').value; var total = document.getElementById('total').value; var esp = verificaEspaco(5); var tabela = document.getElementById('list_produtos'); var row = tabela.rows.length; cont = 0; numColunas = 5; pos = 0; col = 0; lista = ''; for(lin=0;lin<=row-1;lin++){ for(col=0;col<=numColunas;col++){ pos = (lin * 6) + cont lista += document.forms[1].elements[pos].value+'-'; cont++ } cont = 0; } if(nr_nf == '' || serie == '' || nr_rm == '' || nf_desc == '' || esp > 0){ document.getElementById('retorno_gr').innerHTML = 'Preencha todos os campos!'; calculaTotal(); if(esp > 0){ document.getElementById('retorno_gr').innerHTML = 'Insira ao menos um produto!'; } }else{ var parametros = 'lista='+lista+ '&forne='+forne+ '&nr_nf='+nr_nf+ '&serie='+serie+ '&nr_rm='+nr_rm+ '&dt_em='+dt_em+ '&tp_nf='+tp_nf+ '&total='+parseFloat(total)+ '&nf_desc='+nf_desc; xmlHttp.open('POST', 't_lista.php', true); xmlHttp.onreadystatechange = retorno_listaProdutos; xmlHttp.setRequestHeader('Content-type', 'application/x-www-form-urlencoded'); xmlHttp.setRequestHeader('Content-length', parametros.length); xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=iso-8859-1'); xmlHttp.send(parametros); } } function retorno_listaProdutos(){ if(xmlHttp.readyState == 1){ document.getElementById('retorno_gr').innerHTML = '<b>Aguarde...</b>'; } if(xmlHttp.readyState == 4){ var retorno = xmlHttp.responseText; if(retorno.substring(0,2) == 'Ok'){ //retornaBusca('todos','retorno_set.php','retorno_bs') document.getElementById('retorno_gr').innerHTML = retorno; //document.getElementById('nome').style.background=''; //document.getElementById('form_setores').reset(); }else{ document.getElementById('retorno_gr').innerHTML = retorno; } } } </script> <?php require_once("config/config.php"); ?><body> <div id="t_pesquisa_rs"> <div align="center"> <input type="button" id="miniminiza" value="v" onClick="ocultaTabela()" /> </div> </div><div id="id_rs"> <table width="620px" border="0" cellspacing="0" cellpadding="0" align="center" id="tabela" style="display:table;"> <tr> <td><form> </form> <fieldset> <legend><strong> Itens </strong></legend> <table width="100%" border="0" align="center" cellpadding="0" cellspacing="1"> <tr> <td width="4%" bgcolor="#F3F3F3">&nbsp;</td> <td width="15%" bgcolor="#F3F3F3">N&ordm; Patrimonio</td> <td width="12%" bgcolor="#F3F3F3">N&ordm; S&eacute;rie</td> <td width="34%" bgcolor="#F3F3F3">Mateial</td> <td width="9%" bgcolor="#F3F3F3">Volume</td> <td width="11%" bgcolor="#F3F3F3">Peso(Kg)</td> <td width="11%" bgcolor="#F3F3F3">Valor(R$)</td> <td width="4%" align="center"> <img src="../imagens/edit_add.png" alt="Inserir" title="Inserir" onClick="IncluirLinhaTabela()" /></td> </tr> </table> <form> <table width="100%" border="0" align="center" cellpadding="0" cellspacing="5" id="list_produtos"></table> </form> </fieldset> <table width="100%" border="0" align="center" cellpadding="0" cellspacing="5"> <tr> <td width="286" align="center" id="retorno_gr2">&nbsp;</td> <td width="52"><strong>Total:</strong></td> <td width="57"><input name="totalvols" type="text" disabled="disabled" id="totalvols" value="0" size="5" maxlength="5" /></td> <td width="74"><input name="totalpeso" type="text" disabled="disabled" id="totalpeso" value="0" size="5" maxlength="5" /></td> <td width="121"><input name="total" type="text" disabled="disabled" id="total" value="0" size="10" maxlength="10" /></td> </tr> <tr> <td colspan="5" align="center" id="retorno_gr"><input name="button" type="button" id="button2" onClick="listaProdutos()" value="Gravar" /> <input name="button" type="button" id="button2" value="Cancelar" /></td> </tr> </table> <hr /> </td> </tr> </table> <div id="retorno_bs" align="center"></div> </div> desculpe pelo tamanho do tópico. aguardo um help!
×
×
  • Criar Novo...