Here is the form I have...
<form>
<label>Fisrt:</label>
<select class="first">
<option value="0">United</option>
<option value="1">Indi</option>
<option value="2">Kingdom</option>
</select>
<label>Second:</label>
<select class="second">
<option value="0">States</option>
<option value="1">orange</option>
<option value="2">apple</option>
</select>
<input type="text" class="form-control trScr" id="temp" name="temp">
<input type="text" class="form-control trScr" id="bc" name="bc">
</form>
<div id="total">Total: </div>
As you see above, I want to add the numeric value for the dropdown selected with the inserted value for the inputbox. how do i calculate and show the result on div id=total?
Example ..If I select from the dropdown united (0 value) and orange(1 value), And if I insert first and second inputbox respectively(4,2)! I want the result to be 0 + 1 + 4 + 2 = 7. How do i calculate using Jquery? if not Js?
My try... function calculateSum() {
var sum = 0;
//iterate through each textboxes and add the values
$(".trScr").each(function() {
//add only if the value is number
if(!isNaN(this.value) && this.value.length!=0) {
sum += parseFloat(this.value);
console.log(sum);
}
});
//.toFixed() method will roundoff the final sum to 2 decimal places
return sum.toFixed(0);
}
the above show the sum of textbox perfectly, My real problem is how the select can be added with the above code?