Suma De Numeros En varias Cajas De Textos
El Codigo que se muestra nos enseña como validar y sumar números en varias cajas de texto con sus respectivas funciones.
<html>
<head>
<body onload="cargar()">
<form>
<input type='submit' name='enviar1' value='Enviar' OnClick='prueba()'>
<div id='contenedor1'>
</form>
</body>
</head>
</html>
<script type='text/javascript'>
function cargar()
{
var strhtml="";
for (i=1;i<=10;i++)
{
strhtml=strhtml+"<input type='text' id='valor0"+i+"'><br>";
}
document.getElementById('contenedor1').innerHTML=strhtml;
}
function prueba()
{
var suma=0;
for (i=1;i<=10;i++)
{
suma+= parseInt(document.getElementById("valor0"+i).value);
}
alert (suma);
}
</script>
<html>
<head>
<body onload="cargar()">
<form>
<input type='submit' name='enviar1' value='Enviar' OnClick='prueba()'>
<div id='contenedor1'>
</form>
</body>
</head>
</html>
<script type='text/javascript'>
function cargar()
{
var strhtml="";
for (i=1;i<=10;i++)
{
strhtml=strhtml+"<input type='text' id='valor0"+i+"'><br>";
}
document.getElementById('contenedor1').innerHTML=strhtml;
}
function prueba()
{
var suma=0;
for (i=1;i<=10;i++)
{
suma+= parseInt(document.getElementById("valor0"+i).value);
}
alert (suma);
}
</script>
0 Response to Suma De Numeros En varias Cajas De Textos
Publicar un comentario