
05/07/2011, 12:22
|
 | | | Fecha de Ingreso: junio-2011
Mensajes: 150
Antigüedad: 13 años, 8 meses Puntos: 4 | |
valor NAN hola que tal masters!!
tengo las siguientes funciones en un formulario
<script type="text/javascript">
var total = 0;
function comprobarChecks()
{
var checks = document.getElementsByTagName("input"); //recojo todos los input
for(i=0;i<checks.length;i++)
{
if(checks[i].type=="checkbox") //solo contemplo los de tipo checkbox
{
if(checks[i].checked) //si esta checkado agrego a total su valor
total += parseFloat(checks[i].value);
}
}
}
</script>
<script>
var total=0;
function sumar(valor) {
total += valor;
document.formulario.total.value=total;
}
function restar(valor) {
total-=valor;
document.formulario.total.value=total;
}
</script>
<script>
var total2=0;
function sumar1(valor) {
total2 += valor;
document.formulario.total2.value=total2;
}
function restar1(valor) {
total2-=valor;
document.formulario.total2.value=total2;
}
</script>
Mi body... <body onload="comprobarChecks();">
y mis checkbox....
<input name="checkbox1" id="checkbox1" type="checkbox" <?php echo $check1 == '1' ? 'checked' : ''; ?> onclick="if (this.checked) sumar(8.3333333333333333333333333333333); else restar(8.3333333333333333333333333333333)">
<input type="checkbox" id="checkbox2" value="2" name="checkbox2" <?php echo $check2 == '1' ? 'checked' : ''; ?> onclick="if (this.checked) sumar(8.3333333333333333333333333333333); else restar(8.3333333333333333333333333333333)">
<input type="checkbox" id="checkbox3" value="3" name="checkbox3" <?php echo $check3 == '1' ? 'checked' : ''; ?> onclick="if (this.checked) sumar(8.3333333333333333333333333333333); else restar(8.3333333333333333333333333333333)">
.
.
.
.
y mi campo donde voy sumando los checkbox...
<input type=text name=total style="width: 34px"value="<?php echo $fila_campos['porciento_avances']?>">
Cuando cargo mi formulario me aparecen los checkbox con su respectiva cantidad acumulada tal, ahora quiero seguir sumando o restando apartir de la cantidad que guarde que esta en el campo "total" pero me saca NAN y no me hace la suma o resta.. Alguna idea?? |