Ver Mensaje Individual
  #1 (permalink)  
Antiguo 29/06/2011, 10:25
zeichen
 
Fecha de Ingreso: diciembre-2006
Mensajes: 20
Antigüedad: 17 años, 4 meses
Puntos: 0
Suma de valores en arrays

Buenas anteriormente cree un tema y no me respondieron, espero correr con suerte en esta ocasion. Estoy realizando un sistema usuando PHP, JAVASCRIPT y AJAX, tengo un array de textbox en el cual quiero realizar la suma desus valores pero no encuentro como hacerlo!, heeeeeeeeellllpp meee les agradeceria mucho su ayuda. Aqui les coloco el codigo:


POBLACION DIRECTA</div></th>
<td colspan="3" class="Estilo2">&nbsp; </td>
</tr>
<tr>
<th class="label">INST:</th>
<td colspan="3" class="Estilo2"><div align="left">
<input name="poblacion[]" type="text" id="poblacion[]" size="6" />
</div></td>
</tr>
<tr>
<th class="label">NO INST:</th>
<td colspan="3" class="Estilo2"><div align="left">
<input name="poblacion[]" type="text" id="poblacion[]" size="6" />
<img src="imagenes/ayuda.gif" alt="Ayuda" width="18" height="18" onmouseover="muestraAyuda(event, 'beneficiario')" /></div></td>
</tr>
<tr>
<th class="label">Pasantes (cuando aplica):</th>
<td colspan="3" class="Estilo2"><div align="left">
<input name="poblacion[]" type="text" id="poblacion[]" size="6" />
</div></td>
</tr>

poblacion[] es el array al cual le quiero realizar la suma de sus valores.




el codigo de validacion que estaba creando es este pero no me funciona:

function comprobar()

{

var chks = document.getElementsByName('poblacion[]');//here rr[] is the name of the textbox
var total;
for (var i = 0; i<chks.length; i++)
{
total+= chks[i].value;
alert("la suma es," +total);
return false;
}
}