I Expect to get the sum when I click the button but nothing happens. This is however the simplified version of the code I want to use. The values of the textboxes are actually being queried from a database with php. Please F1. Here is the complete code.
<html>
<head>
</head>
<body>
<h1> JavaScript </h1>
<script type="text/javascript">
// Addint an array of values from a text box
function calc(){
var mutli_Credit = document.course_reg.elements['Credit[]'];
var sum = 0, i = 0, len = mutli_Credit.length;
for(i < len; ++i){
sum += parseInt(document.getElementById('Credit[i]).value, 10);
// Use parseFloat if you're dealing with floating point numbers.
}
//alert(sum);
document.getElementById('credit_load').value = sum;
};
</script>
<form name='course_reg' onLoad=''>
MATH101 <input type='text' name='Credit[]' value='3' id='Credit[]' size='3' readonly /><br/>
CSC201 <input type='text' name='Credit[]' value='2' id='Credit[]' size='3' readonly /><br/>
EDU301 <input type='text' name='Credit[]' value='2' id='Credit[]' size='3' readonly /><br/>
<BUTTON onClick='calc()'> CALCULATE </BUTTON>
Total Credit Load:<input type='text' value='' id='credit_load' name='credit_load' size='3' readonly/></p>
</form>
</body>
</html>