Showing Calculated fields in the form

J

Jack

Hi,
I have a asp input form of a financial report. Here most of the fields are
text boxes where the user need to input the values corresponding to an item.
However, there are few items which are calcuated field. Prior to submission
of the information, I would like the user to know what the calculated field
be (based on the information input in text boxes) before submission of the
form. Is there any way to display the calculated value before submission in
ASP? I appreciate in any help. Thanks.
 
R

Ray Costanzo [MVP]

If you want to do it ~before~ submission, you'll need to use client-side
script to calculate the values, i.e. JavaScript, which is off-topic here of
course. But, as a sample:

<form name="formName">
<input name="a" type="text" onchange="hyp();" />
<input name="b" type="text" onchange="hyp();" />
<input name="c" type="text" />

</form>
<script type="text/javascript">
function hyp() {
var a = document.formName.a.value;
var b = document.formName.b.value;
if (a!='' && b!='') {
var c = Math.sqrt(Math.pow(a,2) + Math.pow(b,2));
if(!isNaN(c)) { document.formName.c.value=c; }
}
}
</script>

Ray at work
 
M

mirza i

or you could:

assuming that let's say totvalue = txtbox2 + txtbox1

on updating either txtbox2 or txtbox1 call another asp page passing the two
vars and adding them up in that page and then
passing the three vars back into your original page.

txtbox1 would then be the var1
txtbox2 would then be the var2

and

in the html show the totvalue wherever you want to show it.

also,
at the start of the page have, if var1= "" then | var1=0 | end if
similarly for var2

using this method your data is more secure as all the calcs are done on the
server.

mirzai
 
J

Jack

Thanks to both Ray and Mirza for giving insight to the resolution of problem.
I need to do a test page to check on the above two concepts before
implementing in the finalcial application. Regards.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,567
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top