Auto calculation of radio buttons


hi,

i have order form (no ecommerce) various text fields , 3 radio buttons 3 different freight charges. form handler php.

i've managed value of freight button clicked in email can't work out how add freight charge total or include charge in confirmation email viewer. i've tried sorts of combinations can't freight charge included in total.

grateful advise, thanks.

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=utf-8" />

<title>contact , order online @ hamden estate vineyard 214 dry river road, martinborough</title>

<meta name="description" content="hamden estate vineyard located on dry river terraces approximately 6 kilometres south of martinborough on dry river road. vineyard elevated site has spectacular views tararua ranges" />

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.0/jquery.min.js"></script>

<script src="js/jquery.validate.min.js"></script>

<script src="spryassets/spryvalidationtextfield.js" type="text/javascript"></script>

<script src="spryassets/spryvalidationradio.js" type="text/javascript"></script>

<link href="css-files/main-styles.css" rel="stylesheet" type="text/css" />

<link href="css-files/menu-styling.css" rel="stylesheet" type="text/css" />

<link href="css-files/order-form-css.css" rel="stylesheet" type="text/css" />

<script type="text/javascript">

function mm_validateform() { //v4.0

  if (document.getelementbyid){

    var i,p,q,nm,test,num,min,max,errors='',args=mm_validateform.arguments;

    (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=document.getelementbyid(args[i]);

      if (val) { nm=val.name; if ((val=val.value)!="") {

        if (test.indexof('isemail')!=-1) { p=val.indexof('@');

          if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain e-mail address.\n';

        } else if (test!='r') { num = parsefloat(val);

          if (isnan(val)) errors+='- '+nm+' must contain number.\n';

          if (test.indexof('inrange') != -1) { p=test.indexof(':');

            min=test.substring(8,p); max=test.substring(p+1);

            if (num<min || max<num) errors+='- '+nm+' must contain number between '+min+' , '+max+'.\n';

      } } } else if (test.charat(0) == 'r') errors += '- '+nm+' required.\n'; }

    } if (errors) alert('the following error(s) occurred:\n'+errors);

    document.mm_returnvalue = (errors == '');

} }

</script>

<script language="javascript" type="text/javascript">

<!--

 

/* script copyright (c) paul mcfedries and

logophilia limited (http://www.mcfedries.com/).

permission granted use script long as

this copyright notice remains in place.*/

 

function calculatetotal(frm) {

    var order_total = 0

 

    // run through form fields

    (var i=0; < frm.elements.length; ++i) {

 

        // current field

        form_field = frm.elements[i]

 

        // field's name

        form_name = form_field.name

 

        // "product" field?

        if (form_name.substring(0,4) == "prod") {

 

            // if so, extract price name

            item_price = parsefloat(form_name.substring(form_name.lastindexof("_") + 1))

 

            // quantity

            item_quantity = parseint(form_field.value)

 

            // update order total

            if (item_quantity >= 0) {

                order_total += item_quantity * item_price

            }

        }

    }

     // display total rounded 2 decimal places

    document.getelementbyid("order_total").firstchild.data = "$" + round_decimals(order_total, 2)

}

 

function round_decimals(original_number, decimals) {

    var result1 = original_number * math.pow(10, decimals)

    var result2 = math.round(result1)

    var result3 = result2 / math.pow(10, decimals)

    return pad_with_zeros(result3, decimals)

}

 

function pad_with_zeros(rounded_value, decimal_places) {

 

    // convert number string

    var value_string = rounded_value.tostring()

  

    // locate decimal point

    var decimal_location = value_string.indexof(".")

 

    // there decimal point?

    if (decimal_location == -1) {

      

        // if no, decimal places padded 0s

        decimal_part_length = 0

      

        // if decimal_places greater zero, tack on decimal point

        value_string += decimal_places > 0 ? "." : ""

    }

    else {

 

        // if yes, decimal places padded 0s

        decimal_part_length = value_string.length - decimal_location - 1

    }

  

    // calculate number of decimal places need padded 0s

    var pad_total = decimal_places - decimal_part_length

  

    if (pad_total > 0) {

      

        // pad string 0s

        (var counter = 1; counter <= pad_total; counter++)

            value_string += "0"

        }

    return value_string

}

//-->

</script>

<link href="spryassets/spryvalidationtextfield.css" rel="stylesheet" type="text/css" />

<link href="spryassets/spryvalidationradio.css" rel="stylesheet" type="text/css" />

</head>

<body>

<div id="outer-wrapper-contact-us">

<div id="lh-col-contact-us">

<div id="hamden-estate-title-lh"></div>

<div id="lh-col-image"></div>

<div id="main-menu">

<div class="arrowgreen">

          <ul>

        <li><a href="index.html">home</a></li>

                    <li><a href="index.html">the sibling's story</a></li>

                    <li><a href="about-us.html">about us</a></li>

                    <li><a href="vintage-notes.html">vintage notes</a></li>

                    <li><a href="contact-us.html" title="tools">location map</a></li>

                    <li><a href="contact-us.html">order online</a></li>

              <li><a href="contact-us.html" class="selected" title="contact us">contact us</a></li>

    </ul>

</div>

</div>

</div>

<div id="top-banner-about"><div id="masthead-title-contact-us"></div></div>

<div id="lower-image-contact-us"></div>

<div id="main-content-area-contact-us">

<div class="contact-us-text">

</div>

<div id="contact-text-line-one">at 214 dry river road, martinborough</div>

<div id="contact-text-line-two">(06) 306 8001 or 0274 848 439, or send </div>

<div id="contact-text-line-three"><a href="mailto:info@hamdenestate.co.nz">info@hamdenestate.co.nz</a></div>

<div id="contact-text-line-four"></div>

<div id="contact-text-line-five"></div>

<div id="main-content-area-contact-us-upper">use friendly contact form below order wine us. once have received order email confirmation , order reference number. payments should made directly our account once have received reference number.<br />

</div>

<div id="main-content-area-contact-us-lower"></div>

</div>

<div id="contact-us-rh-image-holder">

<div class="contact-us-rh-image-holder-top">

<a id="contact-us-rh-image-holder-top" href="https://maps.google.co.nz/maps?q=214+dry+river+road,+martinborough&hl=en&client=safari&oe= utf-8&hnear=214+dry+river+rd,+dyerville+5781,+wellington&t=h&z=16" target="_new"></a>

                                        </div>

<div id="contact-us-rh-image-holder-bot"></div>

</div>

<div id="contact-us-content-lower">

  <div id="contact-us-form-holder">

<div id="orderform">

<form action="php-files/contact-form-handler-test.php" id="order" method="post" name="form">

     <p> <span class="field-name-label">name:</span>

<input name="name" type="text" class="name-field" />

<span class="field-name-label">street: </span>

<input name="address" type="text" class="address-one" id="address" />

   </p>

   <p><span class="field-name-label">email:

       </span>

     <label>

       <input name="email" type="text" class="email-field" id="email" onblur="mm_validateform('email','','risemail');return document.mm_returnvalue" />

       <span class="field-name-label">suburb: </span></label>

     <input name="addresstwo" type="text" class="address-two" id="addresstwo" />

     <br />

     <br />

     <span class="field-name-label">phone: </span>

     <input name="phone" type="text" class="phone-field" id="phone" />

     <span class="field-name-label">town/city:</span>

     <input name="addressthree" type="text" class="address-three" id="addressthree" />

   <table width="628" border="0">

     <tr>

       <td width="200" class="wine-name-five">type of wine</td>

       <td width="80"> </td>

       <td width="116" align="center" class="dollar-amount">number<br />

of single <br />

bottles</td>

       <td width="39" class="dollar-amount">price per bottle</td>

       <td width="80" align="center" class="dollar-amount">number<br />

of full <br />

         cases</td>

       <td width="87" align="center" class="dollar-amount">price <br />

         per <br />

         case</td>

       </tr>

     <tr>

       <td class="wine-name-five">chardonnay 2011</td>

       <td><input type="checkbox" name="wine1" value="chardonnay 2011" id="wine1" /></td>

       <td align="center"><input name="prod_chardonnay2011bottles_20" type="text" class="selection-box" onchange="calculatetotal(this.form)" /></td>

       <td class="dollar-amount">$20.00</td>

       <td><input name="prod_chardonnay2011cases_204" type="text" class="selection-box" onchange="calculatetotal(this.form)" /></td>

       <td align="center" class="dollar-amount">$204.00</td>

       </tr>

     <tr>

       <td class="wine-name-five">pino gris 2011</td>

       <td><input type="checkbox" name="wine2" value="pino gris 2011" id="wine2" /></td>

       <td align="center"><input name="prod_pinogris2011bottles_21" type="text" class="selection-box" onchange="calculatetotal(this.form)" /></td>

       <td class="dollar-amount">$21.00</td>

       <td><input name="prod_pinogris2011cases_228" type="text" class="selection-box" onchange="calculatetotal(this.form)" /></td>

       <td align="center" class="dollar-amount">$228.00</td>

       </tr>

     <tr>

       <td class="wine-name-five">sauvigon blanc 2011</td>

       <td><input type="checkbox" name="wine3" value="sauvigon blanc 2011" id="wine3" /></td>

       <td align="center"><input name="prod_sauvigonblanc2011bottles_20" type="text" class="selection-box" onchange="calculatetotal(this.form)" /></td>

       <td class="dollar-amount">$20.00</td>

       <td><input name="prod_sauvigonblanc2011cases_204" type="text" class="selection-box" onchange="calculatetotal(this.form)" /></td>

       <td align="center" class="dollar-amount">$204.00</td>

       </tr>

     <tr>

       <td class="wine-name-five">riesling 2012</td>

       <td><input type="checkbox" name="wine4" value="riesling 2012" id="wine4" /></td>

       <td align="center"><input name="prod_riesling2012bottles_20" type="text" class="selection-box" onchange="calculatetotal(this.form)" /></td>

       <td class="dollar-amount">$20.00</td>

       <td><input name="prod_riesling2012cases_204" type="text" class="selection-box" onchange="calculatetotal(this.form)" /></td>

       <td align="center" class="dollar-amount">$204.00</td>

       </tr>

     <tr>

       <td class="wine-name-five">pino noir 2009</td>

       <td><input type="checkbox" name="wine5" value="pino noir 2009" id="wine5" /></td>

       <td align="center"><input name="prod_pinotnoir2009bottles_25" type="text" class="selection-box" onchange="calculatetotal(this.form)" /></td>

       <td class="dollar-amount">$25.00</td>

       <td><input name="prod_pinotnoir2009cases_250" type="text" class="selection-box" onchange="calculatetotal(this.form)" /></td>

       <td align="center" class="dollar-amount">$250.00</td>

       </tr>

     <tr>

       <td colspan="6" class="wine-name-five">mixed cases available, @ case prices per bottle.</td>

       </tr>

     <tr>

       <td valign="top" class="wine-name-five">mixed case per order:</td>

       <td colspan="5"><label>

         <textarea name="message" id="message" cols="47" rows="5"></textarea>

       </label></td>

       </tr>

     <tr>

       <td class="wine-name-five">freight (per order)<br />         <span class="dollar-amount">please insert 1 in either box</span></td>

       <td colspan="4" class="wine-name-five">- north island

         <table width="58" border="0" align="right">

           <tr valign="middle">

             <td width="48">

</td>

           </tr>

     </table></td> 

       <td>

         <br />

         <span class="radiorequiredmsg">please make selection.</span></span><br />

       </span></td>

       </tr>

     <tr>

       <td> </td>

       <td colspan="4" class="wine-name-five">- south island

         <table width="58" border="0" align="right">

           <tr>

             <td width="35" valign="middle"><span class="dollar-amount">$15.00</span></td>

           </tr>

       </table></td>

       <td><input name="prod_freightcases_15" type="text" onchange="calculatetotal(this.form)" size="1" maxlength="1" /></td>

       </tr>

     <tr class="table-row">

       <td colspan="6"><span class="mixedcase-order">- collection vineyard arrangement</span><span class="free">

north:<input type="radio" value="10" name="call"><br />

south:<input type="radio" value="15" name="call"><br />

pick up:<input type="radio" value="0" name="call"><br />

         <td width="26">

       </td></span>

       </tr>

   </table>

   <p align="right">

<p align="right">  

   <p align="right">

     <input name="submit"  type="submit" class="submit-buton" id="submit" style="width: 120px;" value="submit order" reset>

   </form>

<div id="order-total-wrapper">

<div class="order-total-text" style="text-align: right">

  <div align="left" class="order-total-text-1">total: </div>

  </div>

<div class="order-total-text-2" id="order_total" style="text-align: right">$0.00</div>

<div id="total-payable">total amount payable<br /><br />

<div id="conformation-text">when click "submit" confirmation email sent inbox</div>

</div>

</div>

</div>

</div> 

  </div>

</div>

<div id="footer-links">

<a href="site-map.html" class="rh-vert-border">site map</a>

<a href="contact-us.html" class="rh-vert-border">order online</a>

<a href="contact-us.html" class="rh-vert-border">contact us</a>

<a href="http://www.loudmouse.co.nz/" target="_new">&copy; loudmouse design ltd 2012</a></div>

<script src="js/wineorder.js"></script>

<script>

jquery(function ($) {

    $('#order').validate();

});

var sprytextfield1 = new spry.widget.validationtextfield("sprytextfield1", "none");

</script>

<script type="text/javascript">

var ac1 = new spry.widget.validationradio("radiogroup1",{isrequired:true, minselections:1, maxselections:1, validateon:['blur','change']});

var spryradio2 = new spry.widget.validationradio("spryradio2");

</script>

</body>

</html>

 

php;

<?php

$errors = '';

$myemail = 'sales@tridentsolutions.co.nz'; //<-----put email address here.

if(empty($_post['name'])  ||

   empty($_post['email']) ||

   empty($_post['address']))

{

  

}

 

 

$name = $_post['name']; 

$email_address = $_post['email'];

$phone = $_post['phone'];

$address = $_post['address'];

$addresstwo = $_post['addresstwo'];

$addressthree = $_post['addressthree'];

 

 

$wine1= $_post['wine1'];

$wine2= $_post['wine2'];

$wine3= $_post['wine3'];

$wine4= $_post['wine4'];

$wine5= $_post['wine5'];

$chardonnay_2011_bottles = $_post['prod_chardonnay2011bottles_20'];

$chardonnay_2011_cases = $_post['prod_chardonnay2011cases_204'];

$pino_gris_2011_bottles = $_post['prod_pinogris2011bottles_21'];

$pino_gris_2011_cases = $_post['prod_pinogris2011cases_228'];

$sauvigon_blanc_2011_bottles = $_post['prod_sauvigonblanc2011bottles_20'];

$sauvigon_blanc_2011_cases = $_post['prod_sauvigonblanc2011cases_204'];

$riesling_2012_bottles = $_post['prod_riesling2012bottles_20'];

$riesling_2012_cases = $_post['prod_riesling2012cases_204'];

$pinot_noir_2009_bottles = $_post['prod_pinotnoir2009bottles_25'];

$pinot_noir_2009_cases = $_post['prod_pinotnoir2009cases_250'];

$message = $_post['message'];

$call = $_post['call'];

$totalcost = ($chardonnay_2011_bottles * 20 + $chardonnay_2011_cases * 204) + ($pino_gris_2011_bottles * 21 + $pino_gris_2011_cases * 228) + ($sauvigon_blanc_2011_bottles * 20 + $sauvigon_blanc_2011_cases * 204) + ($riesling_2012_bottles * 20 + $riesling_2012_cases * 204) + ($pinot_noir_2009_bottles * 25 + $pinot_noir_2009_cases * 250) + ($call * 10 + $call * 15 + $call * 0);

 

 

$reply = $_post['email'];

          $replysubject = "auto-reply: hamden estate website";

          $replyfrom = "from: sales@tridentsolutions.co.nz\r\n";

          $replymessage = "dear ".$_post ['name']."\r\n\r\n";

          $replymessage .= "thank placing order hamden estate vineyard. contact shortly reference number , payment details...\r\n\r\n";

          $replymessage .= "";

 

          $replymessage .= "your order details:\r\n\r\n";

          $replymessage .= "wine selection: $wine1\r\n";

          $replymessage .= "bottles: $chardonnay_2011_bottles\r\n";

          $replymessage .= "cases: $chardonnay_2011_cases\r\n\r\n";

 

          $replymessage .= "wine selection: $wine2\r\n";

          $replymessage .= "bottles: $pino_gris_2011_bottles\r\n";

          $replymessage .= "cases: $pino_gris_2011_cases\r\n\r\n";

 

          $replymessage .= "wine selection: $wine3\r\n";

          $replymessage .= "bottles: $sauvigon_blanc_2011_bottles\r\n";

          $replymessage .= "cases: $sauvigon_blanc_2011_cases\r\n\r\n";

 

          $replymessage .= "wine selection: $wine4\r\n";

          $replymessage .= "bottles: $riesling_2012_bottles\r\n";

          $replymessage .= "cases: $riesling_2012_cases\r\n\r\n";

 

          $replymessage .= "wine selection: $wine5\r\n";

          $replymessage .= "bottles: $pinot_noir_2009_bottles\r\n";

          $replymessage .= "cases: $pinot_noir_2009_cases\r\n\r\n";

 

 

    $replymessage .= "freight: $call";

 

 

          $replymessage .= "total $ $totalcost\r\n\r\n";

 

 

 

          $replymessage .= "from folks @ hamden estate\r\n";

          $replymessage .= "sales@tridentsolutions.co.nz\r\n";

          $replymessage .= "http://www.hamdenestate.co.nz\r\n\r\n";

          $replymessage .= "this e-mail automated, please not reply.\r\n";

 

 

 

if (!preg_match(

"/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$/i",

$email_address))

{

    $errors .= "\n error: invalid email address";

}

 

 

if( empty($errors))

{

          $to = $myemail;

          $email_subject = "contact form submission: $name";

          $email_body = "you have received online order via website. here details: ".

 

                                      " \n name: $name

                                        \n email: $email_address

                                        \n phone: $phone

                                        \n address: $address

                                        \n address: $addresstwo

                                                                                                    \n address: $addressthree

                                        \n wine selection: $wine1

                                        \n bottles: $chardonnay_2011_bottles

                                        \n cases: $chardonnay_2011_cases

                                        \n wine selection: $wine2

                                        \n bottles: $pino_gris_2011_bottles

                                        \n cases: $pino_gris_2011_cases

                                        \n wine selection: $wine3

                                        \n bottles: $sauvigon_blanc_2011_bottles

                                        \n cases: $sauvigon_blanc_2011_cases

                                        \n wine selection: $wine4

                                        \n bottles: $riesling_2012_bottles

                                        \n cases: $riesling_2012_cases

                                        \n wine selection: $wine5

                                        \n bottles: $pinot_noir_2009_bottles

                                        \n cases: $pinot_noir_2009_cases

                                        \n message \n $message       

                                                                                                    \n call \n $call

                                                                                          

                                       

                                                                                                    \n client pick up: \n $value = prod_0

                                                                                        \n total $ : $totalcost";

                                                                       

 

$headers = "from: $myemail\n";

          $headers .= "reply-to: $email_address";

          mail($to,$email_subject,$email_body,$headers);

 

mail($reply,$replysubject,$replymessage,$replyfrom);

          //redirect 'thank you' page          $reply = $_post['email'];

 

 

          header('location: contact-form-thank-you.html');

}

?>

 

 

<!doctype html public "-//w3c//dtd html 4.01 transitional//en" "http://www.w3.org/tr/html4/loose.dtd">

<html>

<head>

          <title>contact form handler</title>

</head>

 

 

 

 

<body>

<!-- page displayed if there error -->

<?php

echo nl2br($errors);

?>

</body>

</html>


 

hi gofer, instead of radio buttons mess javascript calculations up. use 'select' list option. should work.

 

so insert 'select delivery option' on form:

 

 

select name="prod_freight_1" onchange="calculatetotal(this.form)">

    <option value="0" selected="selected">collect order $0</option>

<option value="10">north island $10</option>

<option value="15" >south island $15 </option>

 

</select>

 

 

then amend php freight variable retreive correct price:

 

$freight = $_post['prod_freight_1'];



More discussions in Dreamweaver support forum


adobe

Comments

Popular posts from this blog

How to change text Component easybook reloaded *newbee* - Joomla! Forum - community, help and support

PProHeadless.exe has stopped working error when opening projects in Adobe Media Encoder CS6

Preconditions Failed. - Joomla! Forum - community, help and support