By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
428,586 Members | 623 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 428,586 IT Pros & Developers. It's quick & easy.

Calculate inside a form and use the same form as Insert record form

P: n/a
I have 3 fields in an aspx page. The 3. field should be the sum of field A
and field B
I use OnTextChanged to calculate the sum in field3.
At the same time I want to insert the content of theese 3 fields into a row
in a table.
The problem is that I need 'postback is true' on the textfields to get an
immediate calculation and then the insert action is triggered.
reidarT
Nov 30 '06 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Hey reidar,

You don't have to do the postback thing. You can use some javascript
to achieve the same result.

Say you have three textboxes:

txtFirst,txtSecond,txtSum

To get txtSum to be calculated do the following:

In the aspx html code add the following function

<script language=javascript>
function check(){
if(parseInt(document.getElementById('txtFirst').va lue,10)!="NaN" &&
parseInt(document.getElementById('txtSecond').valu e,10)!="NaN"){
document.getElementById('txtSum').value =
parseInt(document.getElementById('txtFirst').value ,10) +
parseInt(document.getElementById('txtSecond').valu e,10)
}
}
</script>

This is basically some javascript that calculate the sum of the first
two textboxes and stores the result in the third. The 10 argument to
parseInt is not redundant ... if you have a number starting with 0 in
either of the text boxes the javascript engine will think it is an
octal number

Then in your code behind do this:

If Not IsPostBack Then
txtFirst.Attributes.Add("onChange", "check()")
txtSecond.Attributes.Add("onChange", "check()")
End If

On Thu, 30 Nov 2006 19:49:41 +0100, "reidarT" <re****@eivon.nowrote:
>I have 3 fields in an aspx page. The 3. field should be the sum of field A
and field B
I use OnTextChanged to calculate the sum in field3.
At the same time I want to insert the content of theese 3 fields into a row
in a table.
The problem is that I need 'postback is true' on the textfields to get an
immediate calculation and then the insert action is triggered.
reidarT
--

Bits.Bytes.
http://bytes.thinkersroom.com
Nov 30 '06 #2

P: n/a
Reidar,

Doing this with "on text change" is in my idea completely foolish over ASPX.
Beside the advise from Rad, you can have a look what Ajax can do for you.
(Just to experiment, because the advise from Rad is in my idea better).

http://ajax.asp.net/

Cor

"reidarT" <re****@eivon.noschreef in bericht
news:Os**************@TK2MSFTNGP02.phx.gbl...
>I have 3 fields in an aspx page. The 3. field should be the sum of field A
and field B
I use OnTextChanged to calculate the sum in field3.
At the same time I want to insert the content of theese 3 fields into a
row in a table.
The problem is that I need 'postback is true' on the textfields to get an
immediate calculation and then the insert action is triggered.
reidarT

Dec 1 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.