<!DOCTYPE html>
<html>
<head>
</head>
<body id="body" οnlοad="init();">
<input type="button" id="b" value="Plus" οnclick="cal();" /><br>
<div id="result">
</div>
<input type="radio" id="plus" name="plusandminus" value="plus"/><span>+</sapn>
<input type="radio" id="minus" name="plusandminus" value="minux"/><span>-</sapn>
<input type="radio" id="multiply" name="multiplyanddivide" value="multiply"/><span>*</sapn>
<input type="radio" id="divide" name="multiplyanddivide" value="divide"/><span>/</sapn>
<br><br>
<script type="text/javascript">
function init() {
for(i=0; i<100; i++) {
checkBox=document.createElement("input");
checkBox.setAttribute("type" , "checkbox");
checkBox.setAttribute("id" , "cb"+i);
checkBox.setAttribute("value" , i);
body.appendChild(checkBox);
span=document.createElement("span");
span.innerHTML=i;
body.appendChild(span);
}
}
function cal() {
if(document.getElementById("plus").checked) {
sum = 0;
for(i=0; i<100; i++) {
cb = document.getElementById("cb"+i);
if(cb.checked) {
sum = parseInt(sum) + parseInt(cb.value);
}
}
document.getElementById("result").innerHTML += sum + " ";
}
if(document.getElementById("minus").checked) {
sum = null;
for(i=0; i<100; i++) {
cb = document.getElementById("cb"+i);
if(cb.checked) {
if(sum == null) {
sum = parseInt(cb.value);
continue;
}
sum = parseInt(sum) - parseInt(cb.value);
}
}
document.getElementById("result").innerHTML += sum;
}
if(document.getElementById("multiply").checked) {
sum = 1;
for(i=0; i<100; i++) {
cb = document.getElementById("cb"+i);
if(cb.checked) {
sum = parseInt(sum) * parseInt(cb.value);
}
}
document.getElementById("result").innerHTML += sum;
}
if(document.getElementById("divide").checked) {
sum = null;
for(i=0; i<100; i++) {
cb = document.getElementById("cb"+i);
if(cb.checked) {
if(sum == null) {
sum = parseInt(cb.value);
continue;
}
sum = parseInt(sum) / parseInt(cb.value);
}
}
document.getElementById("result").innerHTML += sum;
}
}
</script>
</body>
</html>