Hi,
I have a Order Form I want to setup inside my Joomla Site and ChronoForms seems they way to go. I have some valid HTML with Java in it which works, but I am having trouble getting the form to auto calculate on change when in the ChronoForm.
This is what I have extrapolated so far from the working form:
Form Name: TEST_1
HTML Code:
Java Code:
I have modified this from a textbook exercise as I want to develop this a bit more with a few more rows to the calculation, which I can do when this works.
Many Thanks for your help.
I have a Order Form I want to setup inside my Joomla Site and ChronoForms seems they way to go. I have some valid HTML with Java in it which works, but I am having trouble getting the form to auto calculate on change when in the ChronoForm.
This is what I have extrapolated so far from the working form:
Form Name: TEST_1
HTML Code:
<p>Please tell us who you are (<font color="#FF0000">red</font> denotes required information):</p>
<table border="0" cellpadding="0" width="550" id="table1">
<tr>
<td width="340" align="right"><font color="#FF0000">Name</font></td>
<td width="10"> </td>
<td width="200"><input type="text" name="Name" size="30" tabindex="1"></td>
</tr>
<tr>
<td width="340" align="right"><font color="#FF0000">Email</font>
(Your confirmation will be sent here): </td>
<td width="10"> </td>
<td width="200"><input type="text" name="Email" size="30" tabindex="1"></td>
</tr>
<tr>
<td width="340" align="right">Other Contact Info:</td>
<td width="10"> </td>
<td width="200"><input type="text" name="OtherInfo" size="30" tabindex="1"></td>
</tr>
<tr>
<td width="340" align="right"> </td>
<td width="10"> </td>
<td width="200"> </td>
</tr>
</table>
<p>And tell us what you would like:</p>
<table border="0" cellpadding="0" width="550" id="table2">
<tr>
<td width="250" height="31"><b>Item Description</b></td>
<td align="center" width="100" height="31"><b>Quantity</b></td>
<td align="right" height="31" width="60"><b>Price </b></td>
<td align="right" height="31" width="140"><b>Total</b></td>
</tr>
<tr>
<td width="250">Class "A" Widgets</td>
<td align="center" width="100">
<input type="text" name="qtyA" size="5" tabindex="5" onChange="calculate()"></td>
<td align="right" width="60">12</td>
<td align="right" width="140">
<input type="text" name="totalA" size="12" tabindex="99" onChange="calculate()"></td>
</tr>
<tr>
<td width="250">Class "B" Widgets</td>
<td align="center" width="100">
<input type="text" name="qtyB" size="5" tabindex="5" onChange="calculate()"></td>
<td align="right" width="60">13</td>
<td align="right" width="140">
<input type="text" name="totalB" size="12" tabindex="99" onChange="calculate()"></td>
</tr>
<tr>
<td width="250">Class "C" Widgets</td>
<td align="center" width="100">
<input type="text" name="qtyC" size="5" tabindex="5" onChange="calculate()"></td>
<td align="right" width="60">14</td>
<td align="right" width="140">
<input type="text" name="totalC" size="12" tabindex="99" onChange="calculate()"></td>
</tr>
<tr>
<td width="250"> </td>
<td align="center" width="100"> </td>
<td align="right" width="60"> </td>
<td align="right" width="140"> </td>
</tr>
<tr>
<td width="250">
<p align="right"><b>TOTALS:</b></td>
<td align="center" width="100"> </td>
<td align="right" width="60"> </td>
<td align="right" width="140">
<input type="text" name="GrandTotal" size="15" tabindex="99" onChange="calculate()"></td>
</tr>
<td width="250"> </td>
<td align="center" width="100"> </td>
<td align="right" width="60"> </td>
<td align="right" width="140"> </td>
</tr>
</table>
<p> </p>
<table border="0" cellpadding="0" width="550" id="table3">
<tr>
<td width="563">
<p align="center">
<input type="submit" value="Submit" name="subButton" tabindex="50">
<input type="reset" value="Reset" name="resetButton" tabindex="50"></td>
</tr>
</table>
Java Code:
var form = ChronoContact.TEST_1;
function dm(amount)
{
string = "" + amount;
dec = string.length - string.indexOf('.');
if (string.indexOf('.') == -1)
return string + '.00';
if (dec == 1)
return string + '00';
if (dec == 2)
return string + '0';
if (dec > 3)
return string.substring(0,string.length-dec+3);
return string;
}
function calculate()
{
QtyA = 0; QtyB = 0; QtyC = 0;
TotA = 0; TotB = 0; TotC = 0;
PrcA = 12; PrcB = 13; PrcC = 14;
if (document.form.qtyA.value > "")
{ QtyA = document.form.qtyA.value };
document.form.qtyA.value = eval(QtyA);
if (document.form.qtyB.value > "")
{ QtyB = document.form.qtyB.value };
document.form.qtyB.value = eval(QtyB);
if (document.form.qtyC.value > "")
{ QtyC = document.form.qtyC.value };
document.form.qtyC.value = eval(QtyC);
TotA = QtyA * PrcA;
document.form.totalA.value = dm(eval(TotA));
TotB = QtyB * PrcB;
document.form.totalB.value = dm(eval(TotB));
TotC = QtyC * PrcC;
document.form.totalC.value = dm(eval(TotC));
Totamt =
eval(TotA) +
eval(TotB) +
eval(TotC) ;
document.form.GrandTotal.value = dm(eval(Totamt));
}
I have modified this from a textbook exercise as I want to develop this a bit more with a few more rows to the calculation, which I can do when this works.
Many Thanks for your help.