Я создаю калькулятор TCO. Я в состоянии получить первую часть PHP, которая отображает заданные числа в полях ввода и вычисляет переменные в конечный результат просто отлично. Вторая часть, где пользователь может изменить числа в этих входах и затем пересчитать результаты на той же странице, не работает. Вот что я сделал до сих пор:
<?php
// This works like a charm!
// prefill the form inputs
$parnum = "1000000000"; // Revenues
$pirnum = "4.00"; // % Revenue
$pesnum = "10.00"; // % Scope
// calculate the form formula
$hccput = round($parnum * ($pirnum / 100) * ($pesnum / 100));
$hcprice_text = (string)$hccput; // convert into a string
$tothccost = number_format($hcprice_text);
$preput = $hccput;
$preput2 = .535808;
$eqdput = round($preput * $preput2);
$eqdprice_text = (string)$eqdput; // convert into a string
$toteqdhccost = number_format($eqdprice_text);
// create the dynamic bars
$toteqdhcsave = round(100 - ($eqdput / $preput) * 100);
$toteqdhcsave2 = 100 - $toteqdhcsave;
$eqdhcsoutput = $toteqdhcsave2;
$tothcsave = 100;
$toteqdhcper = 'height:' . $toteqdhcsave . '%';
$tothcper = 'height:' . $tothcsave . '%';
?>
<div class="medium-12 columns">
<form id="hard-cost" class="medium-6 columns clearfix" action="<?php $_SERVER['PHP_SELF'];?>" method="post">
<h2 class="text-center">(PHP)</h2>
<div class="slidecontainer">
<div class="small-12 columns">
<label>Revenues</label>
<input type="number" value="<?php echo $parnum; ?>" onchange="handleChange10(this);" min="1" max="10000000000" name="parnumphp" id="parnumphp" />
<label>% Revenue</label>
<input type="number" value="<?php echo $pirnum; ?>" onchange="handleChange11(this);" min="1.00" max="100.00" name="pirnumphp" id="pirnumphp" />
<label>% Scope</label>
<input type="number" value="<?php echo $pesnum; ?>" onchange="handleChange11(this);" min="1.00" max="100.00" name="pesnumphp" id="pesnumphp" />
<input type="button" value="submit" class="button blue-bg white m-bottom" name="hchnumphp" id="hchnumphp" />
</div>
</div>
</form>
<div class="tothc-calcphp medium-6 columns medium-centered">
<h4 class="text-center">Pay <span id="toteqdhcsave"><?php echo $toteqdhcsave2; ?></span>% less</h4>
<ul id="bars">
<li class="small-4 small-push-1 columns">
<div id="toteqdhcper" class="bar" style="<?php echo $toteqdhcper; ?>"></div>
<div class="bar-text">
<h4>Cost 1:<br /> $<span id="toteqdhccost"><?php echo $toteqdhccost; ?></span></h4>
</div>
</li>
<li class="small-4 small-push-3 columns">
<div id="tothcper" class="bar" style="<?php echo $tothcper; ?>"></div>
<div class="bar-text">
<h4>Cost 2:<br /> $<span id="tothccost"><?php echo $tothccost; ?></span></h4>
</div>
</li>
</ul>
</div>
</div>
<?php
// THIS ISN'T WORKING AT ALL!!!
if(isset($_POST['hchnumphp'])){
$parnumphp = $_POST["parnumphp"]; // Revenue
$pirnumphp = $_POST["pirnumphp"]; // % Revenue
$pesnumphp = $_POST["pesnumphp"]; // % Scope
echo "parnumphp is: " . $parnumphp; // TESTING BUT IT"S NOT WORKING
echo "pirnumphp is: " . $pirnumphp; // TESTING BUT IT"S NOT WORKING
echo "pesnumphp is: " . $pesnumphp; // TESTING BUT IT"S NOT WORKING
// calculate the formula
$hccputphp = round($parnumphp * ($pirnumphp / 100) * ($pesnumphp / 100));
$hcprice_textphp = (string)$hccputphp; // convert into a string
$tothccostphp = number_format($hcprice_textphp);
$preputphp = $hccputphp;
$preput2php = .535808;
$eqdputphp = round($preputphp * $preput2php);
$eqdprice_textphp = (string)$eqdputphp; // convert into a string
$toteqdhccostphp = number_format($eqdprice_textphp);
// create the dynamic bars
$toteqdhcsavephp = round(100 - ($eqdputphp / $preputphp) * 100);
$toteqdhcsave2php = 100 - $toteqdhcsavephp;
$eqdhcsoutputphp = $toteqdhcsave2php;
$tothcsavephp = 100;
$toteqdhcperphp = 'height:' . $toteqdhcsavephp . '%';
$tothcperphp = 'height:' . $tothcsavephp . '%';
}
?>
<script>
function handleChange10(input) {
if (input.value < 1) input.value = 1;
if (input.value > 10000000000) input.value = 10000000000;
}
function handleChange11(input) {
if (input.value < 1) input.value = 1;
if (input.value > 100) input.value = 100;
}
</script>