Por que 7? si tu array no tiene esa cantidad de elementos
Supongo, sin ver tu html, que sería algo asi
Código HTML:
Ver original<!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"> <meta http-equiv="content-type" content="text/html; charset=utf-8" />
<script type="text/javascript"> //<![CDATA[
function suma(){
var cArray = new Array();
var pArray = new Array();
var nArray = new Array();
var tArray = new Array();
var totalcompra = 0;
cArray[0] = document.getElementById('c').value;
cArray[1] = document.getElementById('c1').value;
cArray[2] = document.getElementById('c2').value;
cArray[3] = document.getElementById('c3').value;
cArray[4] = document.getElementById('c4').value;
cArray[5] = document.getElementById('c5').value;
pArray[0] = document.getElementById('a').value;
pArray[1] = document.getElementById('a1').value;
pArray[2] = document.getElementById('a2').value;
pArray[3] = document.getElementById('a3').value;
pArray[4] = document.getElementById('a4').value;
pArray[5] = document.getElementById('a5').value;
for (i=0;i<cArray.length;i++)
{
totalcompra = totalcompra + (parseInt(cArray[i]) + parseInt(pArray[i])) ;
//alert(parseInt(cArray[i]) + parseInt(pArray[i]));
}
alert(totalcompra);
}
//]]>
<input type="text" id="a" value="5" /> <input type="text" id="a1" value="5" /> <input type="text" id="a2" value="5" /> <input type="text" id="a3" value="5" /> <input type="text" id="a4" value="5" /> <input type="text" id="a5" value="5" /> <input type="text" id="c" value="8" /> <input type="text" id="c1" value="5" /> <input type="text" id="c2" value="5" /> <input type="text" id="c3" value="5" /> <input type="text" id="c4" value="5" /> <input type="text" id="c5" value="5" />
Saludos