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.
Eu tenho 2 scripts feitos em javascript que funcionam bem sozinhos.
Me surgiu agora a necessidade de uni-los.
um eu adiciono campos ao formulario do orçamento que e esse:
>
var qtdeCamposB = 0;
function addCamposB() {
var objPaiB = document.getElementById("campoPaiB");
//Criando o elemento DIV;
var objFilhoB = document.createElement("div");//Inserindo o elemento no pai:
objPaiB.appendChild(objFilhoB);
//Escrevendo algo no filho recém-criado:
document.getElementById("filhoB"+qtdeCamposB).innerHTML = "<table width='100%' border='0'><tr><td width='16%' class='style12'><input type='text' name='qtd[]' size='10'></td><td width='54%' class='style12'><select name='produto[]' id='id_cliente'><option value='' selected='selected'>Selecione um Produto</option><?php while ($vetorproduto=mysql_fetch_array($sql_produto)) { ?><option value='<?php echo $vetorproduto[id_produto]."_".$vetorproduto[nome]."_".$vetorproduto[valorun]; ?>'><?php echo $vetorproduto[nome]; echo " / "; echo $vetorproduto[valorun]; ?></option><?php } ?></select></td><td width='30%' class='style12'><input type='button' onclick='removerCampoB("+qtdeCamposB+")' value='Apagar'></td></tr></table>";
qtdeCamposB++;
}
function removerCampoB(id) {
var objPaiB = document.getElementById("campoPaiB");
var objFilhoB = document.getElementById("filhoB"+id);
console.log(objPaiB);var removido = objPaiB.removeChild(objFilhoB);
}
e outro que vou digitando em um campo texto ele vai buscando em um <select name> que é esse:
>
function trocaOpcao(valor, objSel) {
for (i=0; i < objSel.length; i++){
qtd = valor.length;
if (objSel.options*.text.substring(0, qtd).toUpperCase() == valor.toUpperCase()) {*
objSel.selectedIndex = i;
break;
}
}
}
minha duvida e como fazer para o trocaopção funcionar dentro do que cria campos:
fiz assim só que nada funciona:
>
var qtdeCamposB = 0;
*function addCamposB() {*
*var objPaiB = document.getElementById("campoPaiB");**document.getElementById("filhoB"+qtdeCamposB).innerHTML = "<table width='100%' border='0'><tr><td width='16%' class='style12'><input type='text' name='qtd[]' size='10'></td><td width='54%' class='style12'><input name='texto' type='text' onKeyUp='trocaOpcao(this.value, document.produto.produto[]);' size='10' /><select name='produto[]' id='id_cliente'><option value='' selected='selected'>Selecione um Produto</option><?php while ($vetorproduto=mysql_fetch_array($sql_produto)) { ?><option value='<?php echo $vetorproduto[nome]."_".$vetorproduto[valorun]; ?>'><?php echo $vetorproduto[nome]; ?></option><?php } ?></select></td><td width='30%' class='style12'><input type='button' onclick='removerCampoB("+qtdeCamposB+")' value='Apagar'></td></tr></table>";**function removerCampoB(id) {*
*var objPaiB = document.getElementById("campoPaiB");*
*var objFilhoB = document.getElementById("filhoB"+id);*
*console.log(objPaiB);*Carregando comentários...