PC Review


Reply
Thread Tools Rate Thread

calculations in form?

 
 
Peter Goldfield
Guest
Posts: n/a
 
      9th Feb 2004
I'm sure this is an easy one 'cos I see it all the time!
When in a form, client puts in amount in text? box, now add 17.5% and show
amount below, then add the 2 items together and place in total box.
Should be a piece of cake?? (FP 2002)
Cheers



 
Reply With Quote
 
 
 
 
Sparky Polastri
Guest
Posts: n/a
 
      9th Feb 2004

"Peter Goldfield" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> I'm sure this is an easy one 'cos I see it all the time!
> When in a form, client puts in amount in text? box, now add 17.5% and show
> amount below, then add the 2 items together and place in total box.
> Should be a piece of cake?? (FP 2002)
> Cheers
>
>
>


Sure. Using JavaScript or ASP or something it's easy.

FrontPage forms dont do that however, so you'll have to find code or code it
by hand.


 
Reply With Quote
 
Jim Buyens
Guest
Posts: n/a
 
      9th Feb 2004
>-----Original Message-----
>I'm sure this is an easy one 'cos I see it all the time!
>When in a form, client puts in amount in text? box, now
>add 17.5% and show amount below, then add the 2 items
>together and place in total box. Should be a piece of
>cake?? (FP 2002)


I suppose you want to do this in JavaScript. If so, here's
some sample code:

<html>
<head>
<script>
function calcTotal(){
if (document.forms[0].txtAmt.value == ""){
document.forms[0].txtScg.value = "";
document.forms[0].txtTot.value = "";
return 0;
}
if (isNaN(document.forms[0].txtAmt.value)){
alert("Amount is not a number.");
document.forms[0].txtAmt.focus();
return 0;
}
document.forms[0].txtScg.value =
document.forms[0].txtAmt.value * .175;
document.forms[0].txtTot.value =
parseFloat(document.forms[0].txtScg.value) +
parseFloat(document.forms[0].txtAmt.value);
}
</script>
</head>
<body>
<form method="POST">
<table>
<tr>
<td>Amount</td>
<td><input type="text" name="txtAmt" size="20"
onblur="calcTotal();"></td>
</tr>
<tr>
<td>Surcharge</td>
<td><input type="text" name="txtScg" size="20"></td>
</tr>
<tr>
<td>Total</td>
<td><input type="text" name="txtTot" size="20"></td>
</tr>
<tr>
<td>&nbsp;</td>
<td><input type="submit" value="Submit"
name="btnSub"></td>
</tr>
</table>
</form>
</body>
</html>

However, this suffers from the flaw that visitors can
overtype all three text boxes. One way of solving this is
to add a readonly="true" attribute to the Surcharge and
Title text boxes, but some browsers ignore this. Another
is to display the Surcharge and Total fields as text, but
not all browsers can replace text that's already on
display.

What's more, these sorts of issues are going to get worse
as you continue developing your application. That's why
the better route is usually to perform such calculations
on the server, using ASP, ASP.NET, PHP, or whatever your
Web server supports.

Jim Buyens
Microsoft FrontPage MVP
http://www.interlacken.com
Author of:
*----------------------------------------------------
|\---------------------------------------------------
|| Microsoft Office FrontPage 2003 Inside Out
||---------------------------------------------------
|| Web Database Development Step by Step .NET Edition
|| Microsoft FrontPage Version 2002 Inside Out
|| Faster Smarter Beginning Programming
|| (All from Microsoft Press)
|/---------------------------------------------------
*----------------------------------------------------

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Calculations on a form Nona Microsoft Access 5 5th Feb 2009 08:21 PM
Sub form calculations not correct on main form =?Utf-8?B?RGFyUw==?= Microsoft Access Form Coding 2 7th Jun 2007 08:25 PM
Form/Sub-form problem save/refresh and calculations =?Utf-8?B?U3RldmVT?= Microsoft Access Forms 6 25th Oct 2006 07:42 PM
Calculations in a Form =?Utf-8?B?VGRhaGxtYW4=?= Microsoft Access 5 12th Jul 2006 03:55 PM
Printing current record from form, after closing form for calculations. Shirly Microsoft Access Form Coding 2 16th Mar 2006 06:37 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:49 PM.