Foros del Web » Programando para Internet » Javascript »

ayuda con funcion para sumar campos de texto

Estas en el tema de ayuda con funcion para sumar campos de texto en el foro de Javascript en Foros del Web. Hola, tenogo el siguiente formulario: <tr> <td colSpan=2> <form name=form2 method=post action=grabar.asp> <table width=100%><tbody> <tr> <TD colSpan=2 height=30 class=clsPageHeader><B>&nbsp;&nbsp; Prevención y Riesgo</B></TD></tr> <tr> <td width=30% ...
  #1 (permalink)  
Antiguo 05/07/2005, 12:51
Avatar de Tarecito  
Fecha de Ingreso: noviembre-2003
Ubicación: Lima - Perú
Mensajes: 443
Antigüedad: 20 años, 5 meses
Puntos: 1
ayuda con funcion para sumar campos de texto

Hola, tenogo el siguiente formulario:

<tr>
<td colSpan=2>
<form name=form2 method=post action=grabar.asp>
<table width=100%><tbody>
<tr>
<TD colSpan=2 height=30 class=clsPageHeader><B>&nbsp;&nbsp; Prevención y Riesgo</B></TD></tr>
<tr>
<td width=30% align=right>Fecha:</td>
<td width=70%><INPUT disabled size=11 value=<% Response.Write(fecha)%> name=fecha></td>
</tr>
<tr>
<td width=30% align=right>Aspectos Generales de Bioseguridad:</td>
<td width=70%>
<SELECT size=1 name=asp_gen_bio onchange="agrega1(this.value)">
<OPTION value=0 selected>Seleccione una opción</OPTION>
<OPTION value=A>A</OPTION>
<OPTION value=B>B</OPTION>
<OPTION value=C>C</OPTION>
</SELECT>&nbsp;<INPUT size=2 name=asp_gen_bio_p readonly>&nbsp;<INPUT size=12 name=asp_gen_bio_tol readonly></td>
</tr>
<tr>
<td width=30% align=right>Saneamiento Básico:</td>
<td width=70%>
<SELECT size=1 name=saneamiento selected onchange="agrega2(this.value);">
<OPTION value=0>Seleccione una opción</OPTION>
<OPTION value=A>A</OPTION>
<OPTION value=B>B</OPTION>
<OPTION value=C>C</OPTION>
</SELECT>&nbsp;<INPUT size=2 name=saneamiento_p readonly>&nbsp;<INPUT size=12 name=saneamiento_tol readonly></td>
</tr>
<tr>
<td width=30% align=right>Tópico y Emergencia:</td>
<td width=70%>
<SELECT size=1 name=topico selected onchange="agrega3(this.value);">
<OPTION value=0>Seleccione una opción</OPTION>
<OPTION value=C>C</OPTION>
<OPTION value=D>D</OPTION>
<OPTION value=E>E</OPTION>
</SELECT>&nbsp;<INPUT size=2 name=topico_p readonly>&nbsp;<INPUT size=12 name=topico_tol readonly>
</td>
</tr>
<tr>
<td class=clsLabel width=30% align=right><font color=red><b>PREVENCIÓN:</b></font></td>
<td width=70%>
<INPUT size=2 name=prevencion value=0 readonly>&nbsp;
<INPUT size=12 name=prevencion_tol readonly></td>
</tr>
<tr>
<td class=clsLabel width=30% align=right><font color=red><b>RIESGO:</b></font></td>
<td width=70%><INPUT size=2 name=riesgo value=0 readonly>&nbsp;
<INPUT size=12 name=riesgo_tol readonly></td>
</tr>
.
.
.
la idea es q segun se elija un valor en los selects, se llenen los input con cierto valor. Lo cual ya lo tengo en una funcion jscript. El problema viene cuando quiero sumar el valor de los inputs y colocarlo en el input llamado "prevencion". Sólo he logrado hacer q en este campo prevencion se coloque el valor de cada select dependiendo del valor q se escoja y sin sumarlos entre los valores del mismo select... peroo no logro sumar entre cada select... no se si me he dejado entender. Aqui les pongo la función (lo tengo en una libreria):

function agrega1(valor) {
tot_prev = 0;
temp = 0;
acum = 0;
tot_riesgo = 0;
if (valor == "0") {
document.form2.asp_gen_bio_p.value="";
document.form2.asp_gen_bio_tol.value="";
}
if (valor == "A") {
document.form2.asp_gen_bio_p.value="8";
document.form2.asp_gen_bio_tol.value="TRIVIAL";
temp = 8;
tot_prev = tot_prev + temp - acum;
acum = temp;
}
if (valor == "B") {
document.form2.asp_gen_bio_p.value="4";
document.form2.asp_gen_bio_tol.value="TOLERABLE";
temp = 4;
tot_prev = tot_prev + temp - acum;
acum = temp;
}
if (valor == "C") {
document.form2.asp_gen_bio_p.value="0";
document.form2.asp_gen_bio_tol.value="MODERADO";
}
document.form2.prevencion.value = tot_prev;
riesgo = (tot_prev/4) + (100 - tot_prev);
document.form2.riesgo.value = riesgo;

}

function agrega2(valor) {
//prev=eval("parseFloat(document.form2.prevencion.va lue)")
temp = 0;
acum = 0;
tot_riesgo = 0;
if (valor == "0") {
document.form2.saneamiento_p.value="";
document.form2.saneamiento_tol.value="";
}
if (valor == "A") {
document.form2.saneamiento_p.value="8"
document.form2.saneamiento_tol.value="TRIVIAL"
temp = 8;
tot_prev = tot_prev + temp - acum;
acum = temp;
}
if (valor == "B") {
document.form2.saneamiento_p.value="4"
document.form2.saneamiento_tol.value="TOLERABLE"
temp = 4;
tot_prev = tot_prev + temp - acum;
acum = temp;
}
if (valor == "C") {
document.form2.saneamiento_p.value="0"
document.form2.saneamiento_tol.value="MODERADO"
}
document.form2.prevencion.value = tot_prev;
riesgo = (tot_prev/4) + (100 - tot_prev);
document.form2.riesgo.value = riesgo;
}

function agrega3(valor) {
if (valor == "0") {
document.form2.topico_p.value=""
document.form2.topico_tol.value=""
}
if (valor == "C") {
document.form2.topico_p.value="12"
document.form2.topico_tol.value="MODERADO"
}
if (valor == "D") {
document.form2.topico_p.value="6"
document.form2.topico_tol.value="IMPORTANTE"
}
if (valor == "E") {
document.form2.topico_p.value="0"
document.form2.topico_tol.value="INTOLERABLE"
}
}

me falta adecuarlo para q sumen entre los valores del select, es aqui done necesito su ayuda. Muchas gracias.
__________________
Tarecito
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 01:06.