PHP - no funciona suma automatica

   
Vista:

no funciona suma automatica

Publicado por jhean carlos (113 intervenciones) el 06/06/2011 17:03:42
que tal como puedo corregir esta suma automatica que esta echo con un script
aqui les dejo el codigo.

lo que hace el codigo es suma las caja de texto y en esta tengo dos filas de cajas de texto, la primera fila suma correctamente pero la segunda no me funciona como puedo corregir esto.

aqui les dejo el codigo
<script language="JavaScript">
var nav4 = window.Event ? true : false;
function acceptNum(evt)
{
var key = nav4 ? evt.which : evt.keyCode;
return (key <= 13 || (key>= 48 && key <= 57));
}
</script>

<script>
function sumar()
{
total=0;

for(a=0;a<12;a++)
{

document.forms[0].elements[a].value=document.forms[0].elements[a].value.split(",").join(".");

if (!isNaN(document.forms[0].elements[a].value))
{
pepe=new Number(document.forms[0].elements[a].value);
total=total+pepe;
document.forms[0].elements["total"].value=total
}
else
{
document.forms[0].elements[a].value=""
///alert ("No introdusca letras, solo se admiten Números.");
}
}
}
</script>
<script>
function opera()
{

total=0;
for(a=0;a<2;a++)
{

document.forms[0].elements[a].value=document.forms[0].elements[a].value.split(",").join(".");
if (!isNaN(document.forms[0].elements[a].value))
{

pepe=new Number(document.forms[0].elements[a].value);

total=total+pepe;

document.forms[0].elements["resp"].value=total
}
else
{
document.forms[0].elements[a].value=""
///alert ("No introdusca letras, solo se admiten Números.");
}
}
}
</script>

</head>

<style type="text/css">
.textbox_normal { background-color:#FFFFFF; }
.textbox_activado { background-color:#FFFFCC;color:#0000FF }
</style>

<body><table width="369" align="center"><form action="javascript:alert('Enviando')"
name="formularo" id="formularo">
<tr>
<td width="29">1</td>
<td width="18"><input name="numero1" type="text" style="text-align:right" onKeyUp=sumar() size="3" maxlength="3" onFocus="this.className='textbox_activado'" onBlur="this.className='textbox_normal'"onKeyPress="return acceptNum(event)"></td>
<td width="18"><input name="numero2" type="text" style="text-align:right" onKeyUp=sumar() size="3" maxlength="3" onFocus="this.className='textbox_activado'" onBlur="this.className='textbox_normal'"></td>
<td width="18"><input name="numero3" type="text" style="text-align:right" onKeyUp=sumar() size="3" maxlength="3"onFocus="this.className='textbox_activado'" onBlur="this.className='textbox_normal'"></td>
<td width="18"><input name="numero4" type="text" id="numero4" style="text-align:right" onKeyUp=sumar() size="3" maxlength="3" onFocus="this.className='textbox_activado'" onBlur="this.className='textbox_normal'"></td>
<td width="18"><input name="numero5" type="text" id="numero5" style="text-align:right" onKeyUp=sumar() size="3" maxlength="3" onFocus="this.className='textbox_activado'" onBlur="this.className='textbox_normal'"></td>
<td width="18"><input name="numero6" type="text" id="numero6" style="text-align:right" onKeyUp=sumar() size="3" maxlength="3" onFocus="this.className='textbox_activado'" onBlur="this.className='textbox_normal'"></td>
<td width="18"><input name="numero7" type="text" id="numero7" style="text-align:right" onKeyUp=sumar() size="3" maxlength="3" onFocus="this.className='textbox_activado'" onBlur="this.className='textbox_normal'"></td>
<td width="18"><input name="numero8" type="text" id="numero8" style="text-align:right" onKeyUp=sumar() size="3" maxlength="3" onFocus="this.className='textbox_activado'" onBlur="this.className='textbox_normal'"></td>
<td width="18"><input name="numero9" type="text" id="numero9" style="text-align:right" onKeyUp=sumar() size="3" maxlength="3" onFocus="this.className='textbox_activado'" onBlur="this.className='textbox_normal'"></td>
<td width="18"><input name="numero10" type="text" id="numero10" style="text-align:right" onKeyUp=sumar() size="3" maxlength="3" onFocus="this.className='textbox_activado'" onBlur="this.className='textbox_normal'"></td>
<td width="18"><input name="numero11" type="text" id="numero11" style="text-align:right" onKeyUp=sumar() size="3" maxlength="3" onFocus="this.className='textbox_activado'" onBlur="this.className='textbox_normal'"></td>
<td width="18"><input name="numero12" type="text" id="numero12" style="text-align:right" onKeyUp=sumar() size="3" maxlength="3" onFocus="this.className='textbox_activado'" onBlur="this.className='textbox_normal'"></td>
<td width="36"><input name="total" type="text" style="text-align:right" size="6" maxlength="6" readonly></td>
</tr>
<tr>
<td>2</td>
<td><input name="n1" type="text" id="n1" style="text-align:right" onKeyUp=opera() onFocus="this.className='textbox_activado'" onBlur="this.className='textbox_normal'"onKeyPress="return acceptNum(event)" size="3" maxlength="3"></td>
<td><input name="n2" type="text" id="n2" style="text-align:right" onFocus="this.className='textbox_activado'" onBlur="this.className='textbox_normal'"onKeyPress="return acceptNum(event)" onKeyUp=opera() size="3" maxlength="3"></td>
<td><input name="n3" type="text" id="n3" style="text-align:right" onFocus="this.className='textbox_activado'" onBlur="this.className='textbox_normal'"onKeyPress="return acceptNum(event)" onKeyUp=sumarq() size="3" maxlength="3"></td>
<td><input name="n4" type="text" id="n4" style="text-align:right" onFocus="this.className='textbox_activado'" onBlur="this.className='textbox_normal'"onKeyPress="return acceptNum(event)" onKeyUp=sumarq() size="3" maxlength="3"></td>
<td><input name="n4" type="text" id="n4" style="text-align:right" onFocus="this.className='textbox_activado'" onBlur="this.className='textbox_normal'"onKeyPress="return acceptNum(event)" onKeyUp=sumarq() size="3" maxlength="3"></td>
<td><input name="n5" type="text" id="n5" style="text-align:right" onFocus="this.className='textbox_activado'" onBlur="this.className='textbox_normal'"onKeyPress="return acceptNum(event)" onKeyUp=sumarq() size="3" maxlength="3"></td>
<td><input name="n6" type="text" id="n6" style="text-align:right" onFocus="this.className='textbox_activado'" onBlur="this.className='textbox_normal'"onKeyPress="return acceptNum(event)" onKeyUp=sumarq() size="3" maxlength="3"></td>
<td><input name="n7" type="text" id="n7" style="text-align:right" onFocus="this.className='textbox_activado'" onBlur="this.className='textbox_normal'"onKeyPress="return acceptNum(event)" onKeyUp=sumarq() size="3" maxlength="3"></td>
<td><input name="n8" type="text" id="n8" style="text-align:right" onFocus="this.className='textbox_activado'" onBlur="this.className='textbox_normal'"onKeyPress="return acceptNum(event)" onKeyUp=sumarq() size="3" maxlength="3"></td>
<td><input name="n9" type="text" id="n9" style="text-align:right" onFocus="this.className='textbox_activado'" onBlur="this.className='textbox_normal'"onKeyPress="return acceptNum(event)" onKeyUp=sumarq() size="3" maxlength="3"></td>
<td><input name="n10" type="text" id="n10" style="text-align:right" onFocus="this.className='textbox_activado'" onBlur="this.className='textbox_normal'"onKeyPress="return acceptNum(event)" onKeyUp=sumarq() size="3" maxlength="3"></td>
<td><input name="n11" type="text" id="n11" style="text-align:right" onFocus="this.className='textbox_activado'" onBlur="this.className='textbox_normal'"onKeyPress="return acceptNum(event)" onKeyUp=sumarq() size="3" maxlength="3"></td>
<td><input name="resp" type="text" style="text-align:right" size="6" maxlength="6" readonly></td>
</tr>
</form>
</table>
<p>&nbsp;</p>
<p>&nbsp;</p>
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder