Предмет: Информатика, автор: kisssaa1

Напишите пожалуйста код задачи) Задача на знание javascript. Пользователь вводит последовательно 10 чисел вывести на экран сумму этих чисел.

Ответы

Автор ответа: ShirokovP
0
http://www.w3.org/1999/xhtml">
<head>
<script>
function doProcess() {
var fields=document.forms[0].getElementsByTagName('INPUT');
var val=0;
var total=0;
for (var i=0;i<fields.length;i++) {
if ((fields[i].type=='text')&&(fields[i].name.indexOf('number')==0)) {
val=parseInt(fields[i].value);
total+=val*1;
}
}
document.forms[0].sum.value = total;
}
</script>
</head>
<body align="center">
<form method = "post" action = "/cgi-bin/formmail" >
<input name = "number0" type = "text" size = "4"
maxlength = "5" />
<input name = "number1" type = "text" size = "4"
maxlength = "5" />
<input name = "number2" type = "text" size = "4"
maxlength = "5" />
<input name = "number3" type = "text" size = "4"
maxlength = "5" />
<input name = "number4" type = "text" size = "4"
maxlength = "5" />
<input name = "number5" type = "text" size = "4"
maxlength = "5" />
<input name = "number6" type = "text" size = "4"
maxlength = "5" />
<input name = "number7" type = "text" size = "4"
maxlength = "5" />
<input name = "number8" type = "text" size = "4"
maxlength = "5" />
<input name = "number9" type = "text" size = "4"
maxlength = "5" />
<br><br>
<input type="button" name="click1" value="Подсчитать" onClick="doProcess()">
<p>
<label>Сумма:
<input name = "sum" type = "text" size = "4"
maxlength = "10" />
</form>
</body>
</html>
Похожие вопросы
Предмет: География, автор: erzanovaasem121
Предмет: Алгебра, автор: andrejemelanov556