Ir para conteúdo

POWERED BY:

Arquivado

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

rd111072

[Resolvido] o que está errado?

Recommended Posts

Tenho esse script abaixo. Está dando esse erro:

 

linha 15, 'subtotalc' não está definido. como podem ver ele está definido aqui:

 

<input type='text' name='subtotalc"+i+"' id='subtotalc"+i+"' value='0' style='width:90px; font-family:Verdana, Arial, Helvetica, sans-serif; font-size:10px; color:#000000; background-color:#CCCCCC; border:#CCCCCC solid 1px' readonly='readonly'/>

É um nome de campo dentro da div my_div.

 

A linha 15:

//Capturando a div principal, na qual os novos divs serão inseridos:
	var camposTextoc = document.getElementById('my_div');   
	my_div.innerHTML = my_div.innerHTML+subtotalc;
}

O script (na íntegra) é esse:

 

<%
	cod_usuario = session("cod_usuario")
%>


<script language="javascript">
var i = 1;
var hiddenc; 
//Definindo quantos campos poderão ser criados (máximo); name='preco"+i+"' id='preco"+i+"' value='0'
var iCamposTotal = 30; 
function changeIt(){
if (i <= iCamposTotal) {
hiddenc = document.getElementById("hiddenc");
my_div.innerHTML = my_div.innerHTML +"<table width='990' border='0' cellpadding='2' cellspacing='2' bordercolor='#FFFFFF' style='font-family:Verdana, Arial, Helvetica, sans-serif; font-size:11px'><tr><td height='25' bgcolor='#CCCCCC'>
<div align='left'><label><input type='text' name='item"+i+"' id='item"+i+"' value='"+i+"' style='width:18px; font-family:Verdana, Arial, Helvetica, sans-serif; font-size:9px; color:#6699FF' readonly='readonly'/></label></div></td>
<td height='25' bgcolor='#CCCCCC'><div align='center'><input type='text' name='codigo"+i+"' id='codigo"+i+"' style='width:80px; font-family:Verdana, Arial, Helvetica, sans-serif; font-size:10px; color:#000000; background-color:#CCCCCC; border:#CCCCCC solid 1px'/></div></td>
<td height='25' bgcolor='#CCCCCC'><div align='center'>R$<input type='text' name='valoru"+i+"' id='valoru"+i+"' onChange='somac("+i+")'  style='width:70px; font-family:Verdana, Arial, Helvetica, sans-serif; font-size:10px; color:#000000; background-color:#CCCCCC; border:#CCCCCC solid 1px'/></div></td>
<td height='25' bgcolor='#CCCCCC'><div align='center'><input type='text' name='quant"+i+"' id='quant"+i+"' onChange='somac("+i+")' style='width:50px; font-family:Verdana, Arial, Helvetica, sans-serif; font-size:10px; color:#000000; background-color:#CCCCCC; border:#CCCCCC solid 1px'/></div></td>
<td height='25' bgcolor='#CCCCCC'><div align='center'><input type='text' name='icmsc"+i+"' id='icmsc"+i+"' onChange='somac("+i+")' style='width:20px; font-family:Verdana, Arial, Helvetica, sans-serif; font-size:10px; color:#000000; background-color:#CCCCCC; border:#CCCCCC solid 1px'/>%</div></td>
<td height='25' bgcolor='#CCCCCC'><div align='center'>R$<input type='text' name='outrasc"+i+"' id='outrasc"+i+"' onChange='somac("+i+")' style='width:70px; font-family:Verdana, Arial, Helvetica, sans-serif; font-size:10px; color:#000000; background-color:#CCCCCC; border:#CCCCCC solid 1px'/></div></td>
<td height='25' bgcolor='#CCCCCC'><div align='center'>R$<input type='text' name='subtotalc"+i+"' id='subtotalc"+i+"' value='0' style='width:90px; font-family:Verdana, Arial, Helvetica, sans-serif; font-size:10px; color:#000000; background-color:#CCCCCC; border:#CCCCCC solid 1px' readonly='readonly'/></div></td>
<td height='25' bgcolor='#CCCCCC'><div align='center'>R$<input type='text' name='valorv"+i+"' id='valorv"+i+"' onChange='somav("+i+")' style='width:70px; font-family:Verdana, Arial, Helvetica, sans-serif; font-size:10px; color:#000000; background-color:#CCCCCC; border:#CCCCCC solid 1px'/></div></td>
<td height='25' bgcolor='#CCCCCC'><div align='center'><input type='text' name='icmsv"+i+"' id='icmsv"+i+"' onChange='somav("+i+")' style='width:15px; font-family:Verdana, Arial, Helvetica, sans-serif; font-size:10px; color:#000000; background-color:#CCCCCC; border:#CCCCCC solid 1px'/>%</div></td>
<td height='25' bgcolor='#CCCCCC'><div align='center'><input type='text' name='comissao"+i+"' id='comissao"+i+"' onChange='somav("+i+")' style='width:20px; font-family:Verdana, Arial, Helvetica, sans-serif; font-size:10px; color:#000000; background-color:#CCCCCC; border:#CCCCCC solid 1px'/>%</div></td>
<td height='25' bgcolor='#CCCCCC'><div align='center'>R$<input type='text' name='outrasv"+i+"' id='outrasv"+i+ "'onChange='somav("+i+")' style='width:70px; font-family:Verdana, Arial, Helvetica, sans-serif; font-size:10px; color:#000000; background-color:#CCCCCC; border:#CCCCCC solid 1px'/></div></td>
<td height='25' bgcolor='#CCCCCC'><div align='center'>R$<input type='text' name='subtotalv"+i+"' id='subtotalv"+i+"' onChange='somav("+i+")' style='width:90px; font-family:Verdana, Arial, Helvetica, sans-serif; font-size:10px; color:#000000; background-color:#CCCCCC; border:#CCCCCC solid 1px'/></div></td>
</tr>
</table>";
//Capturando a div principal, na qual os novos divs serão inseridos:
	var camposTextoc = document.getElementById('my_div');   
	my_div.innerHTML = my_div.innerHTML+subtotalc;
}
 if (hiddenc.value == "") {
			document.getElementById("hiddenc").value = i;
		}else{
			document.getElementById("hiddenc").value += ","+i;
		}
i++;
}
</script>



<script language="JavaScript">
function somac(i){
document.getElementById("subtotalc"+ i).value = '0'
var valoru = parseFloat(document.getElementById("valoru"+ i).value);
var quant = parseFloat(document.getElementById("quant"+ i).value);
var icmsc = parseFloat(document.getElementById("icmsc"+ i).value);
var outrasc = parseFloat(document.getElementById("outrasc"+ i).value);
var valorxquant = valoru * quant
var porcento = icmsc / '100' * valorxquant
document.getElementById("subtotalc"+ i).value = (valorxquant - porcento) + outrasc;

}
</SCRIPT>

<script language="JavaScript">
function somav(i){
document.getElementById("subtotalv"+ i).value = '0'
var valorv = parseFloat(document.getElementById("valorv"+ i).value);
var comissao = parseFloat(document.getElementById("comissao"+ i).value);
var icmsv = parseFloat(document.getElementById("icmsv"+ i).value);
var outrasv = parseFloat(document.getElementById("outrasv"+ i).value);
var porcentoicmsv = icmsv / '100' * valorv
var porcentocomiss = comissao / '100' * valorv
var sub01 = valorv - porcentoicmsv
var sub02 = sub01 - porcentocomiss
document.getElementById("subtotalv"+ i).value = sub02 - outrasv;
}
</SCRIPT>

<script language="JavaScript">
function orcamentoc(){
hiddenc = document.getElementById("hiddenc");

//Convertendo os campos do hidden em um array:
var obterParametros = new Array();
var subTotal = new Array();
var iCount;
var descFinal = "";
var total = 0;

var iPar = 0;
	for (iCount = 0; iCount < hiddenc.value.length; iCount++) {
		if(hiddenc.value.substr(iCount,1) != ",") {
			obterParametros[iPar] = hiddenc.value.substr(iCount,1);
			iPar++;
		}
	
	}	

	//Somando os valores:
	for (iCount = 0; iCount < obterParametros.length; iCount++){
		subTotal[iCount] = parseInt(document.getElementById("subtotalc"+obterParametros[iCount]).value);
		total += subTotal[iCount];
		document.getElementById("totalc").value = "Total: R$ "+total+",00";
	}
	

	
}
</script> 

<!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">
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
		<title>ADEF-RIO Acesso Vendedor</title>
		
	<style type="text/css">
<!--
body {
	background-image: url(imagens/bg_azul.gif);
	background-repeat: repeat-x;
}
-->
	</style>

	<link href="borda.css" rel="stylesheet" type="text/css" />
	<link href="fonte.css" rel="stylesheet" type="text/css" />
	</head>
	
<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
	<form name="form" action="post" method="">
	<table width="1000" border="0" cellpadding="0" cellspacing="0">
	  
	  <tr>
		<td width="412"><span class="canto-top-meio"><img src="imagens/adef.gif" width="135" height="72" /></span></td>
		<td colspan="2" valign="bottom"><div align="right"><strong><font color="#4770BF" size="4" face="Arial, Helvetica, sans-serif"><%=session("nome_usuario")%></font></strong></div></td>
		</tr>
	  <tr>
		<td class="borda"> </td>
		<td colspan="2" valign="bottom" class="borda"></td>
	  </tr>
	  <tr>
		<td><b class="fonte-titulo"><font color="#4770BF">Cálculo de Preço</font></b></td>
		<td colspan="2" valign="bottom"><a href="principal.asp"><img src="imagens/casa.gif" alt="Retorna para tela principal" width="19" height="20" border="0" align="right" /></a></td>
		</tr>
	  <tr>
		<td colspan="3"><table width="500" border="0" align="right" cellpadding="2" cellspacing="2">
		<tr>
		  <td width="41%"><font color="#666666" size="2" face="Verdana, Arial, Helvetica, sans-serif"><strong>Nº do Pedido:</strong></font></td>
		  <td width="59%"><font color="#666666" size="2" face="Verdana, Arial, Helvetica, sans-serif"><strong>Nº do Processo: <input type="text" name="processo" id="processo" style="width:100px; font-family:Verdana, Arial, Helvetica, sans-serif; font-size:10px; color:#666666; border: #666666 1px solid" /></strong></font></td>
		  </tr>
		<tr>
		  <td> </td>
		  <td> </td>
		  </tr>
		<tr>
		  <td><font color="#666666" size="2" face="Verdana, Arial, Helvetica, sans-serif"><strong>Médico: <input type="text" name="medico" id="medico" style="width:130px; font-family:Verdana, Arial, Helvetica, sans-serif; font-size:10px; color:#666666; border: #666666 1px solid" /></strong></font></td>
		  <td><font color="#666666" size="2" face="Verdana, Arial, Helvetica, sans-serif"><strong>Clínica/Hospital: <input type="text" name="clinica" id="clinica" style="width:130px; font-family:Verdana, Arial, Helvetica, sans-serif; font-size:10px; color:#666666; border: #666666 1px solid" /></strong></font></td>
		  </tr>
	  </table></td>
	  </tr>
	  
	  <tr>
		<td colspan="3"> </td>
		</tr>
	  
	  <tr>
		<td colspan="3"> </td>
	  </tr>
	</table>
	<table width="990" border="0" cellspacing="0" cellpadding="0">
  <tr>
	<td><img src="imagens/menu.gif" /></td>
  </tr>
</table>

   
	
<div id="my_div"></div>
	 <br />
	 <table width="990" border="0" cellspacing="0" cellpadding="0">
	   <tr>
		 <td width="282"><table width="100" border="0" cellspacing="0" cellpadding="0">
		   <tr>
			 <td> </td>
			 <td><input type="button" value="+" onClick="changeIt()"/></td>
			 <td> </td>
		   </tr>
		 </table>
		 <div align="right"></div></td>
		 <td width="283"><div align="right"><font color="#666666" size="2" face="Verdana, Arial, Helvetica, sans-serif"><strong><font color="#333333">Preço de custo:</font>
			<input type="text" name="totalc" id="totalc" onChange="orcamentoc()" style="width:130px; font-family:Verdana, Arial, Helvetica, sans-serif; font-size:10px; color:#666666; border: #666666 1px solid" />
		 </strong></font></div></td>
		 <td width="425"><div align="right"><font color="#666666" size="2" face="Verdana, Arial, Helvetica, sans-serif"><strong><font color="#333333">Preço de venda:</font>
		  <input type="text" name="medico4" id="medico4" style="width:130px; font-family:Verdana, Arial, Helvetica, sans-serif; font-size:10px; color:#666666; border: #666666 1px solid" />
		 </strong></font></div></td>
	   </tr>
	 </table>
	 <br />
	 <br />
	 <table width="990" border="0" cellspacing="0" cellpadding="0">
	   <tr>
		 <td width="456"><label></label></td>
		 <td width="534"><table width="500" border="0" align="right" cellpadding="0" cellspacing="0">
		   <tr>
			 <td width="278"><div align="right"><strong><font size="2" face="Verdana, Arial, Helvetica, sans-serif">Total:</font></strong></div></td>
			 <td width="140"><div align="right"><font color="#666666" size="2" face="Verdana, Arial, Helvetica, sans-serif"><strong>
			   <input type="text" name="medico2" id="medico2" style="width:130px; font-family:Verdana, Arial, Helvetica, sans-serif; font-size:10px; color:#666666; border: #666666 1px solid" /> <input type="text" name="hiddenc" id="hiddenc" value="">
			 </strong></font></div></td>
			 <td width="82"><div align="right">
			   <input type="submit" name="button3" id="button3" value="Salvar" />
			 </div></td>
		   </tr>
		 </table></td>
	   </tr>
	 </table>
</form>
</body>

</html>

Compartilhar este post


Link para o post
Compartilhar em outros sites

Consegui resolver. Criei uma var na linha 15, assim:

 

//Capturando a div principal, na qual os novos divs serão inseridos:

var subtotalc = document.getElementById("subtotalc"+ i).value;

var camposTextoc = document.getElementById('my_div');

my_div.innerHTML = my_div.innerHTML+subtotalc;

}

 

Mas agora fica aparecendo um zerinho embaixo de cada linha dinâmica que crio. Porquê?

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.