<html>
<head>
<title>Calculator</title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.2/jquery-ui.min.js"></script>
<script type="text/javascript" src="js/jquery.form.js"></script>
<script type="text/javascript">
// prepare the form when the DOM is ready
$(document).ready(function() {
var options = {
target: '#divCalculator', // target element(s) to be updated with server response
success: showResponse, // post-submit callback
// other available options:
//url: url // override for form's 'action' attribute
//type: type // 'get' or 'post', override for form's 'method' attribute
//dataType: null // 'xml', 'script', or 'json' (expected server response type)
//clearForm: true // clear all form fields after successful submit
//resetForm: true // reset the form after successful submit
// $.ajax options can be used here too, for example:
//timeout: 3000
};
// bind to the form's submit event
$('#calculator').submit(function() {
// inside event callbacks 'this' is the DOM element so we first
// wrap it in a jQuery object and then invoke ajaxSubmit
$(this).ajaxSubmit(options);
// !!! Important !!!
// always return false to prevent standard browser submit and page navigation
return false;
});
});
// post-submit callback
function showResponse(responseText, statusText, xhr, $form) {
// for normal html responses, the first argument to the success callback
// is the XMLHttpRequest object's responseText property
// if the ajaxSubmit method was passed an Options Object with the dataType
// property set to 'xml' then the first argument to the success callback
// is the XMLHttpRequest object's responseXML property
// if the ajaxSubmit method was passed an Options Object with the dataType
// property set to 'json' then the first argument to the success callback
// is the json data object returned by the server
}
function convert() {
with (document.calculator) {
if (U.value == 0) {
Xo1.value = XO.value;
Xo2.value = XO.value*0.3048;
Dt1.value = DT.value;
Dt2.value = DT.value*25.4;
} else {
Xo1.value = XO.value/0.3048;
Xo2.value = XO.value;
Dt1.value = DT.value/25.4;
Dt2.value = DT.value;
}
}
//document.calculator.submit();
return true;
}
function units() {
with (document.calculator) {
if (U.value == 0) {
XO.value = XO.value/0.3048;
DT.value = DT.value/25.4;
} else {
XO.value = XO.value*0.3048;
DT.value = DT.value*25.4;
}
}
//document.calculator.submit();
return true;
}
</script>
<?php
$U = $_POST['U'];
$CB = $_POST['CB'];
$SR = $_POST['SR'];
$XO = $_POST['XO'];
$Xo1 = $_POST['Xo1'];
$Xo2 = $_POST['Xo2'];
$DT = $_POST['DT'];
$Dt1 = $_POST['Dt1'];
$Dt2 = $_POST['Dt2'];
if(isset($XO)) {
include 'handler.php';
} else {
$U = 0;
$CB = "DEF";
$SR = 32;
$XO = 20;
$Xo1= ($U==0 ? $XO : $XO/0.3048);
$Xo2 = ($U==1 ? $XO : $XO*0.3048);
$DT = 2.875;
$Dt1 = (U==0 ? $DT : $DT/25.4);
$Dt2 = (U==1 ? $DT : $DT*25.4);
$Z1 = 200;
$Z2 = 287.5;
$Z3 = 57.5;
$Z4 = 1840;
}
$english = ($U==0 ? "SELECTED" : "" );
$metric = ($U==1 ? "SELECTED" : "" );
$cb_A = ( $CB=="ABC" ? "SELECTED" : "" );
$cb_D = ( $CB=="DEF" ? "SELECTED" : "" );
$cb_G = ( $CB=="GHI" ? "SELECTED" : "" );
$sr_12 = ( $SR=="12" ? "SELECTED" : "" );
$sr_18 = ( $SR=="18" ? "SELECTED" : "" );
$sr_20 = ( $SR=="20" ? "SELECTED" : "" );
$sr_32 = ( $SR=="32" ? "SELECTED" : "" );
$sr_44 = ( $SR=="44" ? "SELECTED" : "" );
$sr_56 = ( $SR=="56" ? "SELECTED" : "" );
$sr_64 = ( $SR=="64" ? "SELECTED" : "" );
$sr_86 = ( $SR=="86" ? "SELECTED" : "" );
$sr_100 = ( $SR=="100" ? "SELECTED" : "" );
$sr_120 = ( $SR=="120" ? "SELECTED" : "" );
$sr_144 = ( $SR=="144" ? "SELECTED" : "" );
?>
</head>
<body>
<div id="divCalculator">
<form action="handler.php" target="calculator" method="POST" id="calculator" name="calculator">
<span style="color:#0000CC">USER INPUTS:</span>
<br /><br />
U = <select id="U" name="U" size="1" onChange="units(); $('#calculator').submit();">
<option <? echo $english ?> value="0">English</option>
<option <? echo $metric ?> value="1">Metric</option>
</select>
<br /><br />
CB = <select id="CB" name="CB" onChange="$('#calculator').submit();">
<option <? echo $cb_A ?> value="ABC">ABC</option>
<option <? echo $cb_D ?> value="DEF">DEF</option>
<option <? echo $cb_G ?> value="GHI">GHI</option>
</select>
<br /><br />
SR = <select id="SR" name="SR" onChange="$('#calculator').submit();">
<? switch ($CB) {
case "ABC":
echo "<option $sr_12 value='12'>12</option>";
echo "<option $sr_18 value='18'>18</option>";
break;
case "DEF":
echo "<option $sr_20 value='20'>20</option>";
echo "<option $sr_32 value='32'>32</option>";
echo "<option $sr_44 value='44'>44</option>";
echo "<option $sr_56 value='56'>56</option>";
break;
case "GHI":
echo "<option $sr_64 value='64'>64</option>";
echo "<option $sr_86 value='86'>86</option>";
echo "<option $sr_100 value='100'>100</option>";
echo "<option $sr_120 value='120'>120</option>";
echo "<option $sr_144 value='144'>144</option>";
break;
} ?>
</select>
<br /><br />
XO = <input class="input" id="XO" name="XO" type="text" value='<? echo $U==0 ? number_format("$Xo1",0,'.','') : number_format("$Xo2",0,'.','') ?>' size="8" onChange="convert(); $('#calculator').submit();">
<br />
DT = <input class="input" id="DT" name="DT" type="text" value='<? echo $U==0 ? number_format("$Dt1",3,'.','') : number_format("$Dt2",2,'.','') ?>' size="8" onChange="convert(); $('#calculator').submit();">
<br /><br /><br />
<span style="color:#0000CC">CALCULATION RESULTS:</span>
<br /><br />
Z1 (XO*10) = <? echo "$Z1" ?>
<br />
Z2 (DT*100) = <? echo "$Z2" ?>
<br />
Z3 (XO*DT) = <? echo "$Z3" ?>
<br />
Z4 (SR*XO*DT) = <? echo "$Z4" ?>
<br /><br /><br />
<span style="color:#0000CC">UNIT CONVERSION RESULTS:</span>
<br /><br />
Xo1 = <input type="text" name="Xo1" value='<? echo "$Xo1" ?>' size="8" tabindex="6">
<br />
Xo2 = <input type="text" name="Xo2" value='<? echo "$Xo2" ?>' size="8" tabindex="6">
<br /><br />
Dt1 = <input type="text" name="Dt1" value='<? echo "$Dt1" ?>' size="8" tabindex="6">
<br />
Dt2 = <input type="text" name="Dt2" value='<? echo "$Dt2" ?>' size="8" tabindex="6">
<br /><br />
</form>
</div>
</body>
</html>
|