Link to home
Start Free TrialLog in
Avatar of Manju
ManjuFlag for India

asked on

Sum of 5 textbox values to another textbox in ASP

Team,

I just have a simple page with 5 textbox's where user have to enter numeric number(from 1 to 3 - Single digit number). Based onchange on those textbox, i have a another textbox which needs to display the sum of all the textbox values without the page being refresh. Kindly help.

Thanks
Manjunath
Avatar of Wikkard
Wikkard
Flag of Australia image

You can do this with some simple javascript. Assuming that your textboxes have ids like text1, text2 etc.
<input type=text id=text1 value=0>
<input type=text id=text2 value=0>
<input type=text id=text3 value=0>
<input type=text id=text4 value=0>
<input type=text id=text5 value=0>
<input type=text id=resultBox value=0>
<script language=javascript>
function SumBoxes(){
resultBox.Value = text1.value + text2.value + text3.value + text4.value + text5.value;
}
</script>

This is a bit sloppy, and would be better using document.text1.value, I know.
ASKER CERTIFIED SOLUTION
Avatar of Wikkard
Wikkard
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Manju

ASKER

Wikkard,

Awesome. I checked this code in a blank page and it works fantastic. However in my actual asp page, total is getting calculated. my mistake. coz im getting the numbers for textbox thru a combobox value.

On change in 5 different combobox, value is getting stored in 5 different text box which in turn should get added and final result should be in 6th textbox. pls help
Glad to help.
You should be able to add onchange="SumBoxes" to the comboboxes.
Then the SumBoxes function will be called whenever you change a value. (You might need to modify the function SumBoxes to first copy the value from your combobox into your textbox - so that it has the most recent value.)
Avatar of Manju

ASKER

U Rock !