Forums

A form that can calculate ?

lidosofia 24 Aug, 2008
Hi,

I wonder....
does anyone have a sample of a form like this..

You have a type="text" input and in there you write ..1,or 2,or 10 dvd's.
a dvd costs 5 euro.
so if people write 10 then it should show....total = 50 euro , automatically...
Does such a form excist?
GreyHead 24 Aug, 2008
Hi lidosofia,

Sure, you need a little snippet of JavaScript - there have been a few similar things in the forums here, or a Google search on 'javascript calculate total' will turn up hundreds. Here's one example at random.

Bob
lidosofia 24 Aug, 2008
that looks good..thanks🙂
timwatson 18 Sep, 2008
I have modified the form mentioned above, but I'm not sure how to get the values of the quantities in the email. The email returns just the names of the input fields, not the values as well (in my case, it is not returning the quantities of each product that were input, which I need). Please let me know if you are able to help, and/or if you need more info from me.

Thanks so much!
tim

Here's my form:
http://www.logochairs.com/index.php?option=com_chronocontact&chronoformname=Testform

Here is the code I used in the form HTML:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>

<body>

<FORM>

<TABLE BORDER =0>

<TD COLSPAN=3></TD>

<TR><TD width="67" ALIGN="CENTER"><B>
    <div align="left">Quantity:</FONT></div></TD>

<TD width="320" ALIGN="CENTER"><B>
  <div align="left">Tent Part Selections </div></TD><TD width="60" ALIGN="CENTER"><div align="right"><B>Price<BR>
    (each)</B></div></TD></TR>
<TR>
<TD ALIGN="CENTER"><input value="0" type=TEXT name="PROD_SP_4.99" size=3 maxlength=3 onchange="CalculateTotal(this.form)" /></TD>
<TD>Tent Part #1 - <strong>Washer</strong> - <em>TP01-99</em> </TD>
<TD ALIGN="RIGHT">$4.99</TD>
</TR>
<TR><TD ALIGN="CENTER"><INPUT value="0" TYPE=TEXT NAME="PROD_SPMG_4.99" SIZE=3 MAXLENGTH=3 onChange="CalculateTotal(this.form)"></TD>
<TD>Tent Part #2 - <strong>Main Leg 42 1/2"</strong> - <em>TP0246-99</em></TD>
<TD ALIGN="RIGHT">$4.99</TD>
</TR>
<TR><TD ALIGN="CENTER"><INPUT value="0" TYPE=TEXT NAME="PROD_SPCR_4.99" SIZE=3 MAXLENGTH=3 onChange="CalculateTotal(this.form)"></TD>
  <TD>Tent Part #3 - <strong>Lower Canopy Beam</strong> - <em>TP03-99</em></TD>
<TD ALIGN="RIGHT">$4.99</TD>
</TR>
<TR><TD ALIGN="CENTER"><INPUT value="0" TYPE=TEXT NAME="PROD_SW_3.99" SIZE=3 MAXLENGTH=3 onChange="CalculateTotal(this.form)"></TD>
  <TD>Tent Part #4 - <strong>Beam Connector</strong> - <em>TP04-99</em></TD>
<TD ALIGN="RIGHT">$3.99</TD>
</TR>
<TR><TD ALIGN="CENTER"><INPUT value="0" TYPE=TEXT NAME="PROD_SWMG_3.99" SIZE=3 MAXLENGTH=3 onChange="CalculateTotal(this.form)"></TD>
  <TD>Tent Part #5 - <strong>Upper Canopy Beam</strong> - <em>TP05-99</em> </TD>
<TD ALIGN="RIGHT">$3.99</TD>
</TR>
<TR><TD ALIGN="CENTER"><INPUT value="0" TYPE=TEXT NAME="PROD_RY_4.99" SIZE=3 MAXLENGTH=3 onChange="CalculateTotal(this.form)"></TD>
  <TD>Tent Part #6 - <strong>Corner Support Beam</strong> - <em>TP06-99</em></TD>
<TD ALIGN="RIGHT">$4.99</TD>
</TR>
<TR><TD ALIGN="CENTER"><INPUT value="0" TYPE=TEXT NAME="PROD_KT_4.99" SIZE=3 MAXLENGTH=3 onChange="CalculateTotal(this.form)"></TD>
  <TD>Tent Part #7 - <strong>Scissor Beam 36"</strong> - <em>TP07-99</em></TD>
<TD ALIGN="RIGHT">$4.99</TD>
</TR>
<TR><TD ALIGN="CENTER"><INPUT value="0" TYPE=TEXT NAME="PROD_KCR_4.50" SIZE=3 MAXLENGTH=3 onChange="CalculateTotal(this.form)"></TD>
  <TD>Tent Part #8 - <strong>Canopy Top Connector</strong> - <em>TP08-99</em></TD>
<TD ALIGN="RIGHT">$4.50</TD>
</TR>
<TR><TD ALIGN="CENTER"><INPUT value="0" TYPE=TEXT NAME="PROD_KA_4.99" SIZE=3 MAXLENGTH=3 onChange="CalculateTotal(this.form)"></TD>
  <TD>Tent Part #9 - <strong>O-Ring Lock</strong> - <em>TP09-99</em></TD>
<TD ALIGN="RIGHT">$4.99</TD>
</TR>

<TR><TD ALIGN="CENTER"><INPUT value="0" TYPE=TEXT NAME="PROD_tp1099_4.99" SIZE=3 MAXLENGTH=3 onChange="CalculateTotal(this.form)"></TD>
  <TD>Tent Part #10 - <strong>Plastic Leg Insert</strong> - <em>TP10-99</em></TD>
<TD ALIGN="RIGHT">$4.99</TD>
</TR>

<TR><TD ALIGN="CENTER"><INPUT value="0" TYPE=TEXT NAME="PROD_AG_2.99" SIZE=3 MAXLENGTH=3 onChange="CalculateTotal(this.form)"></TD>
  <TD>Tent Part #11 - <strong>44" lower leg</strong> - <em>TP1144-99</em></TD>
<TD ALIGN="RIGHT">$2.99</TD>
<TR><TD><BR></TD><TD>TOTAL</TD><TD ALIGN="RIGHT"><INPUT TYPE=TEXT NAME=TOTAL SIZE=10 onFocus="this.form.elements[0].focus()"></TD>
</TABLE>

<P>

<INPUT TYPE=RESET VALUE="CLEAR FORM">
<input name="submit" value="Submit" type="submit">

</FORM>


</body>
</html>


[attachment=0]chronoformsimage.jpg[/attachment]
GreyHead 18 Sep, 2008
Hi timwatson,

Remove everything before and after the <form> and </form> tags and remove those tags as well (ChronoForms & Joomla provide all this top and bottom code and repeating it will cause problems).

Put quotes round your attribute values - particularly name="TOTAL" in the total field. This will let ChronoForms recognise the field correctly.

Bob
timwatson 18 Sep, 2008
Thank you for the help. I did those two things, and it did add the total to the email, but I am still missing the quantity of each product...still just getting the field name or the alias for it. Anything else I may be missing? Here's what my email looks like now after those revisions.

PROD_SP_4.99
PROD_SPMG_4.99
PROD_SPCR_4.99
PROD_SW_3.99
PROD_SWMG_3.99
PROD_RY_4.99
PROD_KT_4.99
PROD_KCR_4.50
PROD_KA_4.99
Tent Part TP10-99 - Plastic Leg Insert
PROD_AG_2.99
TOTAL 84.84


Submitted by 64.221.222.178
GreyHead 19 Sep, 2008
Hi Tim,

One step forward, I know what the problem is - just haven't found the answer yet.

The '.' in the field names are being converted into '_' somewhere. If you turn debug on* and look at the $_POST array that the form is sending back you'll see that the field names look like [PROD_SP_4_99] wheras they 'should' be like [PROD_SP_4.99]

The '.' is valid in a field name and I'm not sure where the change is taking place. I'll dig a bit more later.

Bob

* I think that you have an invalid redirect on your form, you'll need to remove this before you can see the debug output.
timwatson 19 Sep, 2008
I see what you are talking about. Unfortunately, the form uses that part of the field name to calculate totals so I can't change it. I did change it for a moment to confirm it was the problem and it did start to show me the quantity. Now if we can just figure out why the periods are being converted to underscores...

thanks for your help!!
tim
timwatson 24 Sep, 2008
Anyone have any idea what could be causing the period "." in the field names to be converted to underscores "_"? Please help if you have any idea how to fix this...

thanks!
Tim
Max_admin 24 Sep, 2008
Hi Tim,

I have no idea but when you turn debug on, do you see the posted names with _ instead of . too ?
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
GreyHead 25 Sep, 2008
Hi Tim,

Here's a possible workaround. In your JavaScript replace
item_price = parseFloat(form_name.substring(form_name.lastIndexOf("_") + 1))
with
item_price = parseFloat(form_name.substring(form_name.lastIndexOf("_") + 1))/100
and now convert your prices to the form 1299 (no decimal point) e.g. PROD_SW_399

NB: all the prices must have the cents included for this to work e.g. 1200 for 12.00

Bob
This topic is locked and no more replies can be posted.

VPS & Email Hosting 20% discount

{item:title} {images:#}