add up data in a form

E

Eric Willems

I want to add up data in a form but I don't know how to do that. For
example: if some wants to order 1 time product X and 2 times product Y, I
want to present a total price before the submit of the form. The form/data
will be presented in an E-mail to me. I use frontpage.

Regards
 
T

Trevor L.

Yes, you can do it, but in Javascript.

It is not difficult, but I would need a bit of time to write and test it
(about 10minutes) . I am off to shops now - here in Australia. If you are on
the other side of the world (e.g.USA), I can probably answer while you are
asleep.

Not sure about the form to EMail bit. I have seen discussions on this but
haven't tried it myself. (I am not a business peson, just an amateur web
junkie)
 
T

Trevor L.

I have tried but I can't do it.

I think you need code like this:
<html>
<head>
<script type="text/javascript">
function validate()
{x=document.myForm
x.total.value = +x.amount.value*x.cost.value}
</script>
</head>
<body>
<form name="myForm" action="" onsubmit="validate()">
Enter Amount:<input type="text" name="amount" size="20" value=""><br>
Enter Cost: <input type="text" name="cost" size="20" readonly=readonly
value= "2.00"><br>
Total Value: <input type="text" name="total" size="20" value=""><br>
<input type="submit" value="Submit">
</form>
</body>
</html>

But the problem is that neither the box "amount" nor "total" retain the
value. During the execution of the code, the values are there (as tested by
alerts) but on completion of the function, both boxes are blank.

I am confused.
I can't help you and I can't understand what is wrong.

Can someone help me too please.
 
S

Stefan B Rusynko

See http://irt.org/script/form.htm#6




|I want to add up data in a form but I don't know how to do that. For
| example: if some wants to order 1 time product X and 2 times product Y, I
| want to present a total price before the submit of the form. The form/data
| will be presented in an E-mail to me. I use frontpage.
|
| Regards
|
|
 
T

Trevor L.

With a bit of guidance from other posts here is my revised code

<html>
<head>
<script type="text/javascript">
function addup()
{
x=document.myForm
x.total.value = +x.amount.value*x.cost.value
alert(x.total.value)
}
</script>
</head>
<body>
<form name="myForm" action="">
Enter Amount:<input type="text" name="amount" size="20" value=""><br>
Enter Cost: <input type="text" name="cost" size="20" readonly=readonly
value= "2.00"><br>
Total Value: <input type="text" name="total" size="20" value=""><br>
<input type="button" value="Add" onclick = "addup()">
</form>
</body>
</html>

It may be better to have a different event to trigger the addup function.
e.g. tabbing out of a field. You would also need to modify this for more
than one amount and value
 
Top