[Solved] Calculations on webpage using javascript


As per what i have understood by your last comment.

You should have different ids for third and fourth box i.e. #val3 , #val4 respectively.

So it would be somewhat like this.
See this updated FIDDLE of yours.

Entering the value 4,5,10,5 respectively in the 4 boxes, your subtotal would be 70 as expected.

Just a note: call the function calcSum only when all the four fields are provided. Put the conditions over there otherwise it would return NaN(not a number) even if one field is missing.

if(val1 && val2 && val3 && val4){
    // do your calculation and return the sum
}
else{
    alert("please fill all the fields :)");
}

3

solved Calculations on webpage using javascript