Click to See Complete Forum and Search --> : Displaying a Calculated field in a web form
abiodunode
June 3rd, 2007, 01:56 PM
Hello guys,
I have 2 fields namely "unit price" and "quantity".
I want to display the product of these 2 fields in another field called "amount" on the same form.
I wish to disply the calculated value in this third field once the user tabs into it.
I will appreciate urgent help...please.
Thanks.
Biodun
mcmcom
June 4th, 2007, 11:03 AM
well you would start by getting the total price in your code
double price = double.Parse(this.txtPrice.Text.ToString());
int qty = int.Parse(this.txtQty.Text.ToString());
double total = price * qty;
//display the total in a field
this.txtTotal.Text = total.ToString("C");
im not sure about the event to Tab in to the control, but the above code would go in an event handler. Note that code is not tested. you may have to play with the casts.
hth,
mcm
Shuja Ali
June 4th, 2007, 11:24 AM
You can use onBlur event of the textbox. The onblur event triggers, once the cursor leaves the text box. So you can write this code for the onblur event of both the text boxes, quantity and unit price.
swamivishal1
June 7th, 2007, 08:23 AM
You can use onBlur event of the textbox. The onblur event triggers, once the cursor leaves the text box. So you can write this code for the onblur event of both the text boxes, quantity and unit price.
The onBlur will serve the purpose but it will raise a post back since it is a server side event , because you only need to provide the calculated value in the third textbox, I suggest you to use the client side Script at the onfocus event of the third textbox. that will improve the performance and will not raise the postback.
Shuja Ali
June 7th, 2007, 08:53 AM
The onBlur will serve the purpose but it will raise a post back since it is a server side event , because you only need to provide the calculated value in the third textbox, I suggest you to use the client side Script at the onfocus event of the third textbox. that will improve the performance and will not raise the postback.
No onblur is a JavaScript event and will not raise a postback event.
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.