Click to See Complete Forum and Search --> : Calculating an order form


padi908586
11-16-2003, 03:13 PM
Hi, I am new to this, but hope someone can help me.

I try to generate a form where a user clicks a check box. This returns a value (number) in a field.

Now I want that all numbers are calculated in the third field.

I hope someone can help me.

I have done this so far :

<html>

<head>
</head>

<body>
<form method="POST" action="--WEBBOT-SELF--" onSubmit="location.href='_derived/nortbots.htm';return false;" webbot-onSubmit>
<input TYPE="hidden" NAME="VTI-GROUP" VALUE="0"><!--webbot bot="SaveResults" endspan i-checksum="43374" --><p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
</p>
<table border="0" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="100%">
<tr>
<td width="50%" bordercolor="#FFFFFF">
<input type="checkbox" name="c1" onclick="total1.value='€ 250'"
<span lang="en-gb" value="ON">Article One - € 250</td>
<td width="50%" bordercolor="#FFFFFF">
<input name="total1" size="20" style="float: right"></td>
</tr>
<tr>
<td width="50%" bordercolor="#FFFFFF">
<input type="checkbox" name="c2" onclick="total2.value='€ 400'"
<span lang="en-gb" value="ON">Article Two - € 400 </td>
<td width="50%" bordercolor="#FFFFFF">
<input name="total2" size="20" style="float: right"></td>
</tr>
<tr>
<td width="50%" bordercolor="#FFFFFF">&nbsp;</td>
<td width="50%" bordercolor="#FFFFFF">
</td>
</tr>
</table>
<p><input type="submit" value="Submit" name="B1"><input type="reset" value="Reset" name="B2"></p>
</form>
<p>&nbsp;</p>
</h4>

</form>


<p dir="ltr">
&nbsp;</p>
</body>

</html>

Charles
11-16-2003, 03:51 PM
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta name="Content-Script-Type" content="text/javascript">
<title>Example</title>

<style type="text/css">
<!--
fieldset {display:block; padding:1em; margin:1em; width:15em}
label {display:block; margin:1em 0em}
input {display:block}
-->
</style>

<script type="text/javascript">
<!--
String.prototype.reverse = function () {return this.split('').reverse().join('')};

function Euros (d) {this.ammount = typeof d == 'number' ? d : Number(d.toString().replace(/[,\u20ac]/g, ''))};

Euros.prototype.valueOf = function () {return this.ammount};

Euros.prototype.toString = function () {
if (isNaN (this.ammount)) return NaN.toString();
var l = Math.floor(Math.abs(this.ammount)).toString();
var r = Math.round((Math.abs(this.ammount) % 1) * 100).toString();
return [(this.ammount < 0 ? '-' : ''), '\u20ac', (l.length > 4 ? l.reverse().match(/\d{1,3}/g).join(',').reverse() : l),'.', (r < 10 ? '0' + r : r)].join('');
}
// -->
</script>

<form action="">
<div>
<fieldset>
<legend>Articles</legend>
<label><input id="a1" onclick="this.form.total.value = new Euros(this.checked ? new Euros(this.form.total.value) + Number (this.value) : new Euros(this.form.total.value) - this.value)" type="checkbox" value="250">Article One</label>
<label><input id="a2" onclick="this.form.total.value = new Euros(this.checked ? new Euros(this.form.total.value) + Number (this.value) : new Euros(this.form.total.value) - this.value)" type="checkbox" value="350">Article Two</label>
<label><input id="a3" onclick="this.form.total.value = new Euros(this.checked ? new Euros(this.form.total.value) + Number (this.value) : new Euros(this.form.total.value) - this.value)" type="checkbox" value="450">Article Three</label>
</fieldset>

<fieldset>
<legend>JavaScript Generated Total</legend>
<label>Total<input id="total" readonly type="text"></label>
</fieldset>

<fieldset>
<button type="submit">Submit</button>
<button type="reset">Reset</button>
</fieldset>
</div>
</form>

padi908586
11-16-2003, 04:17 PM
Thats great and will help me.

Thanks a lot