Duda con sumas

30/05/2008 - 23:56 por Elva Pascacio | Informe spam
Hola que tal!,
Espero me puedan ayudar ya que me estoy quebrando la cabeza y ya no
encuentro la solución.

El problema es el siguiente, tengo una funcion e javascript que me suma 2
cajas de texto y el resultado me lo pone en otra, lo que quiero hacer es algo
más dinámico, dentro de mi código ASP tengo lo siguiente:

<%do while not RS.EOF contador = contador + 1 %>
<tr>
<td class="SubEncabezado"><input name="txtCuota<%=contador%>" type="text"
value="<%=RS("Quote")%>" size="10" readonly></td>
<td class="SubEncabezado"><input name="txtCuotaAjustCatego" type="text"
value="" size="10" onFocus="this.style.background ='#FFFF99';empiezaCalc();"
onBlur="this.style.background='white';ParaCalc();"></td>
<td class="SubEncabezado"><input name="txtCumpAjustCatego<%=contador%>"
type="text" value="" size="10" onFocus="this.style.background
='#FFFF99';empiezaCalc();"
onBlur="this.style.background='white';ParaCalc();"></td>
</tr>
<% RS.MoveNext
Loop%>

en donde los campos de texto txtCuota y txtCumpAjustCatego les agregue el
contador para que sean de nombre diferente, por ahora solo sumo los campos
txtCuota1 y txtCumpAjustCatego1, quiero que me haga la operación por todos
los campos si el ciclo son de 10 que sean la suma de los 20 campos de texto,
mi función en javascript es la siguiente:

function calc(){
one = document.main.txtCumpAjustCatego1.value;
two = document.main.txtCuota1.value;


document.main.txtCuotaAjustCatego1.value = ((one * 1) * (two * 1))/100;
}

Espero haberme hecho entender, agradecere su ayuda.

Gracias ! =)

Preguntas similare

Leer las respuestas

#6 Matias Iacono
02/06/2008 - 23:25 | Informe spam
Lo que no veo es donde escribes la variable "contador", para luego hacer el
bucle con el JavaScript.

Sin saber el rango de controles a recorrer, la funcion en javascript no te
funcionara correctamente.

Saludos.

Matías Iacono
Microsoft MVP
Orador Regional INETA
http://mvpfiles.spaces.live.com


"Elva Pascacio" wrote:

aHI TE VA

<table width="90%" align="center">
<tr class="HeaderFormulario2">
<td colspan="6">Ajuste Categoría</td>
</tr>
<tr class="HeaderFormulario2">
<td>Categoría</td>
<td align="center">Cuota</td>
<td align="center">Real</td>
<td align="center">% Cumplimiento</td>
<td align="center">Cuota Ajustada</td>
<td align="center">% Cumplimiento Ajustado</td>
</tr>
<% set RS3=ConsultarSQL("exec SP 1,"&Periodo&","&Zona&"")
%>
<%do while not RS.EOF
contador = contador + 1 %>
<tr>
<td class="SubEncabezado"><%=RS("valor1")%></td>
<td class="SubEncabezado"><input name="txtCuota<%=contador%>"
id="txtCuota<%=contador%>" type="text" value="<%=RS("valor2")%>" size="10"
readonly></td>
<td class="SubEncabezado"><input name="txtNReal" type="text"
value="<%=S("valor3")%>" size="10" readonly></td>
<td class="SubEncabezado"><input name="txtCumplimiento" type="text"
value="<%=RS("valor4")%>" size="10" readonly></td>
<td class="SubEncabezado"><input
name="txtCuotaAjustCatego<%=contador%>" id="txtCuotaAjustCatego<%=contador%>"
type="text" value="" size="10" onFocus="this.style.background
='#FFFF99';empiezaCalc();"
onBlur="this.style.background='white';ParaCalc();"></td>
<td class="SubEncabezado"><input
name="txtCumpAjustCatego<%=contador%>" id="txtCumpAjustCatego<%=contador%>"
type="text" value="" size="10" onFocus="this.style.background
='#FFFF99';empiezaCalc();"
onBlur="this.style.background='white';ParaCalc();"></td>
</tr>
<% RS.MoveNext
Loop
RS.close
set RS = nothing
%>
</table>

"Matias Iacono" wrote:

> Podrias colocar TODO el codigo HTML resultante de tu pagina?
>
> Saludos.
>
> Matías Iacono
> Microsoft MVP
> Orador Regional INETA
> http://mvpfiles.spaces.live.com
>
>
> "Elva Pascacio" wrote:
>
> > Matias,
> >
> > Aplique lo que me hiciste favor de responder a mi pregunta pero me aparece
> > el error de "Object Required" en:
> >
> > one = document.getElementById('txtCumpAjustCatego' + i).value;
> >
> > No reconoce el objeto de texto
> >
> > Tambien ya le agregue en el código html al objeto de texto un id
> >
> > <td class="SubEncabezado"><input name="txtCumpAjustCatego<%=contador%>"
> > id="txtCumpAjustCatego<%=contador%>" type="text" value="" size="10"
> > onFocus="this.style.background ='#FFFF99';empiezaCalc();"
> > onBlur="this.style.background='white';ParaCalc();"></td>
Respuesta Responder a este mensaje
#7 Elva Pascacio
03/06/2008 - 00:16 | Informe spam
Matias,

Hola!, te envío todo el código de mi página, la forma se llama main, el
código que me hiciste favor de pasar por el momento lo tengo comentariado por
que me marcaba el error que anteriormente te describi.

Muchas gracias

<%@ Language=VBScript %>
<%Option Explicit%>
<%
Dim RV,Periodo,PeriodoDes,GteReg,Zona,contador,contador1,contador3
Dim RS1,RS2,RS3
RV = Request.QueryString("Vend")
Periodo = Request.QueryString("Time")
PeriodoDes = Request.QueryString("TimeDes")
Zona = Request.QueryString("Zona")
contador = 0
contador1 = 0
contador3 = 0
%>
<!-- #include file="Header.asp"-->
<script language="JavaScript">
<!--

function empiezaCalc(){
interval = setInterval("calc()",1);
}

/*function calc(){
var _sumaTotal = 0;

for (var i = 0; i < 3; i++)
{
one = document.getElementById('txtCumpAjustCatego' + i).value;
two = document.getElementById('txtCuota' + i).value;
_sumaTotal += ((one * 1) * (two * 1))/100;
}

document.main.txtCuotaAjustCatego1.value = _sumaTotal;
//document.getElementById('txtCuotaAjustCatego' + i).value = _sumaTotal;
}*/
function calc(){
one = document.main.txtCumpAjustCatego1.value;
two = document.main.txtCuota1.value;


document.main.txtCuotaAjustCatego1.value = ((one * 1) * (two * 1))/100;
}


function ParaCalc(){
clearInterval(interval);
}


<table width="90%" align="center">
<tr class="HeaderFormulario2">
<td colspan="6">Ajuste Categoría</td>
</tr>
<%
set RS1=ConsultarSQL("exec SP 1,"&Periodo&","&Zona&"")
%>
<tr class="HeaderFormulario2">
<td>Categoría</td>
<td align="center">Cuota</td>
<td align="center">Real</td>
<td align="center">% Cumplimiento</td>
<td align="center">Cuota Ajustada</td>
<td align="center">% Cumplimiento Ajustado</td>
</tr>
<%do while not RS1.EOF
contador = contador + 1
%>
<tr>
<td><%=RS1("Valor")%></td>
<td><input name="txtCuota<%=contador%>" id="txtCuota<%=contador%>"
type="text" value="<%=RS1("Valor2")%>" size="10" readonly></td>
<td><input name="txtNReal" type="text" value="<%=RS1("Valor3")%>" size="10"
readonly></td>
<td><input name="txtCumplimiento" type="text" value="<%=RS1("Valor4")%>"
size="10" readonly></td>
<td><input name="txtCuotaAjustCatego<%=contador%>"
id="txtCuotaAjustCatego<%=contador%>" type="text" value="" size="10"
onFocus="this.style.background ='#FFFF99';empiezaCalc();"
onBlur="this.style.background='white';ParaCalc();"></td>
<td><input name="txtCumpAjustCatego<%=contador%>"
id="txtCumpAjustCatego<%=contador%>" type="text" value="" size="10"
onFocus="this.style.background ='#FFFF99';empiezaCalc();"
onBlur="this.style.background='white';ParaCalc();"></td>
</tr>
<% RS1.MoveNext
Loop
RS1.close
set RS1 = nothing
%>
</table>

<table width="90%" border="0">
<tr>
<td height="47"> </td>
<td align="right">
<input name="Submit" type="image"
src="ImgCV/btn_ajustar.GIF"onClick="validar='ajustar';" WIDTH="77"
HEIGHT="27">
</td>
</tr>
</table>
<!--#INCLUDE FILE="Footer.asp" -->

"Matias Iacono" wrote:

Lo que no veo es donde escribes la variable "contador", para luego hacer el
bucle con el JavaScript.

Sin saber el rango de controles a recorrer, la funcion en javascript no te
funcionara correctamente.

Saludos.

Matías Iacono
Microsoft MVP
Orador Regional INETA
http://mvpfiles.spaces.live.com


"Elva Pascacio" wrote:

> aHI TE VA
>
> <table width="90%" align="center">
> <tr class="HeaderFormulario2">
> <td colspan="6">Ajuste Categoría</td>
> </tr>
> <tr class="HeaderFormulario2">
> <td>Categoría</td>
> <td align="center">Cuota</td>
> <td align="center">Real</td>
> <td align="center">% Cumplimiento</td>
> <td align="center">Cuota Ajustada</td>
> <td align="center">% Cumplimiento Ajustado</td>
> </tr>
> <% set RS3=ConsultarSQL("exec SP 1,"&Periodo&","&Zona&"")
> %>
> <%do while not RS.EOF
> contador = contador + 1 %>
> <tr>
> <td class="SubEncabezado"><%=RS("valor1")%></td>
> <td class="SubEncabezado"><input name="txtCuota<%=contador%>"
> id="txtCuota<%=contador%>" type="text" value="<%=RS("valor2")%>" size="10"
> readonly></td>
> <td class="SubEncabezado"><input name="txtNReal" type="text"
> value="<%=S("valor3")%>" size="10" readonly></td>
> <td class="SubEncabezado"><input name="txtCumplimiento" type="text"
> value="<%=RS("valor4")%>" size="10" readonly></td>
> <td class="SubEncabezado"><input
> name="txtCuotaAjustCatego<%=contador%>" id="txtCuotaAjustCatego<%=contador%>"
> type="text" value="" size="10" onFocus="this.style.background
> ='#FFFF99';empiezaCalc();"
> onBlur="this.style.background='white';ParaCalc();"></td>
> <td class="SubEncabezado"><input
> name="txtCumpAjustCatego<%=contador%>" id="txtCumpAjustCatego<%=contador%>"
> type="text" value="" size="10" onFocus="this.style.background
> ='#FFFF99';empiezaCalc();"
> onBlur="this.style.background='white';ParaCalc();"></td>
> </tr>
> <% RS.MoveNext
> Loop
> RS.close
> set RS = nothing
> %>
> </table>
>
> "Matias Iacono" wrote:
>
> > Podrias colocar TODO el codigo HTML resultante de tu pagina?
> >
> > Saludos.
> >
> > Matías Iacono
> > Microsoft MVP
> > Orador Regional INETA
> > http://mvpfiles.spaces.live.com
> >
> >
> > "Elva Pascacio" wrote:
> >
> > > Matias,
> > >
> > > Aplique lo que me hiciste favor de responder a mi pregunta pero me aparece
> > > el error de "Object Required" en:
> > >
> > > one = document.getElementById('txtCumpAjustCatego' + i).value;
> > >
> > > No reconoce el objeto de texto
> > >
> > > Tambien ya le agregue en el código html al objeto de texto un id
> > >
> > > <td class="SubEncabezado"><input name="txtCumpAjustCatego<%=contador%>"
> > > id="txtCumpAjustCatego<%=contador%>" type="text" value="" size="10"
> > > onFocus="this.style.background ='#FFFF99';empiezaCalc();"
> > > onBlur="this.style.background='white';ParaCalc();"></td>
email Siga el debate Respuesta Responder a este mensaje
Ads by Google
Help Hacer una pregunta AnteriorRespuesta Tengo una respuesta
Search Busqueda sugerida