Order Calculator
Calculates total cost of order based on shipping cost data
HTML
<link rel="stylesheet" href="http://netdna.bootstrapcdn.com/twitter-bootstrap/2.3.1/css/bootstrap-combined.min.css">
<script src="http://netdna.bootstrapcdn.com/twitter-bootstrap/2.3.1/js/bootstrap.min.js"></script>
<script src="http://parallelable.com/ebp/js/priceWeightData.js"></script>
<form role="form" name="calc" method="POST" class="calculator-form form-horizontal">
<fieldset>
<!-- Form Name -->
<?php if ($_SERVER['HTTP_X_REQUESTED_WITH'] != 'XMLHttpRequest'): ?>
<legend>Расчет суточной нормы калорий для женщин и мужчин</legend>
<?php endif; ?>
<!-- Appended Input-->
<div class="form-group">
<label class="col-md-4 control-label" for="age">Возраст</label>
<div class="col-md-4">
<div class="input-group">
<input id="age" name="age" class="form-control" placeholder="" type="text" required="">
<span class="input-group-addon">лет</span>
</div>
</div>
</div>
<!-- Multiple Radios -->
<div class="form-group">
<label class="col-md-4 control-label" for="sex">Пол</label>
<div class="col-md-4">
<div class="radio">
<label for="sex-0">
<input type="radio" name="sex" id="sex-0" value="man" checked="checked">
<span></span>
Мужской
</label>
</div>
<div class="radio">
<label for="sex-1">
<input type="radio" name="sex" id="sex-1" value="wooman">
<span></span>
Женский
</label>
</div>
</div>
</div>
<!-- Text input-->
<div class="form-group">
<label class="col-md-4 control-label" for="weight">Вес</label>
<div class="col-md-4">
<input id="weight" name="weight" type="text" placeholder="в килограммах" class="form-control input-md" required="">
</div>
</div>
<!-- Text input-->
<div class="form-group">
<label class="col-md-4 control-label" for="height">Рост</label>
<div class="col-md-4">
<input id="height" name="height" type="text" placeholder="в сантиметрах" class="form-control...
JavaScript
/* --------- CALC --------- */
function isNumeric(num, fieldPrompt, fieldName) {
var regTest=/(^\d+$)|(^\d+\.\d+$)/
if (regTest.test(num))
return true;
else {
if (fieldPrompt) {
alert(fieldPrompt + " Must be a valid number");
}
return false;
}
}
function calculate(form){
// oForm = form;
var age = parseInt(form.age.value*1);
var weight = parseInt(form.weight.value*1);
var height = parseInt(form.height.value*1);
// sm = parseInt(oForm.sm.value*1);
if (!isNumeric(age,"age:"))
return false;
else if ( (age <= 12) || (age > 80)) {
alert("Введите возраст между 13 и 80 лет");
return false;
}
if (!isNumeric(height,"Вес"))
return false;
else if (!height) {
alert("Введите Рост");
return false;
}
if (!isNumeric(weight,"Weight:"))
return false;
else if ( (weight <= 40) || (weight > 500) ) {
alert("Введите вес между 41 и 500 кг");
return false;
}
if (form.sex[0].checked)
result = 5 + (10 * weight) + (6.25 * height) - (5 * age);
else
result = - 161 + (10 * weight) + (6.25 * height) - (5 * age);
var maintain = result * form.load_step.options[form.load_step.selectedIndex].value;
rockBottom = (weight*2.22)*8;
result_1 = Math.round(maintain);
loseFat = maintain - (maintain*0.20)
if (loseFat < rockBottom) loseFat = rockBottom;
result_2 = Math.round(loseFat);
var extLoseFat = maintain - (maintain*0.40)
if (extLoseFat < rockBottom)
extLoseFat = rockBottom;
result_3 = Math.round(extLoseFat);
var GainFat = maintain*1.2;
if (GainFat < rockBottom)
GainFat = rockBottom;
result_4 = Math.round(GainFat);
/* var gain = maintain + (maintain*0.20)
s4 = Math.round(gain);*/
jQuery('.form_result').show(400,function(){
switch($('#objective').val()){
case '1' :
$label_text = 'Не изменяя вес';
$otput_result = result_1;
break;
case '2' :
$label_text = 'Для похудения';
...