-2
I have a form with four numeric fields, ncr11
, ncr22
, ncr33
and ncr44
. There is still another field in the form, ncr
, that will receive a total value, which corresponds to the sum of all the first four fields. The sum I made with PHP and was informed in another question that should keep the action
of the blank form and execute the code on the same page, however, when refreshing the page, my result field always turns blank.
What I would like to do is that when the user entered the values, the result field was automatically updated.
<?php
$crTot = "";
if($_POST){
$cr1 = $_POST['ncr11'];
$cr2 = $_POST['ncr22'];
$cr3 = $_POST['ncr33'];
$cr4 = $_POST['ncr44'];
$crTot = $cr1+$cr2+$cr3+$cr4;
echo $crTot;
}
?>
<form method="post" action="">
<div id="circulantes">
<div class="ativocirculante" id="ativocirculante">
<h2>ATIVO CIRCULANTE<input type="text" placeholder="R$ 0,00" id="ac" readonly/></h2>
<h4>Ativo Errático (Financeiro) <input type="text" placeholder="R$ 0,00 aplicações" id="ae"/></h4>
<h4>Disponíveis (Caixa e Bancos)<input type="text" placeholder="R$ 0,00" id="disp"/></h4>
<h3>ACO<input type="text" placeholder="R$ 0,00" id="aco" readonly/></h3>
<h4>Contas a receber<input type="text" placeholder="R$ 0,00" id="cr" name="ncr" value="<?php echo $crTot;?>" readonly/></h4>
<h4 id="cr1">Até 30 dias<input type="text" placeholder="R$ 0,00" id="cr11" name="ncr11"/></h4>
<h4 id="cr2">31 a 60 dias<input type="text" placeholder="R$ 0,00" id="cr22" name="ncr22"/></h4>
<h4 id="cr3">61 a 90 dias<input type="text" placeholder="R$ 0,00" id="cr33" name="ncr33"/></h4>
<h4 id="cr4">Acima de 90 dias<input type="text" placeholder="R$ 0,00" id="cr44" name="ncr44"/></h4>
<h4>Estoque<input type="text" placeholder="R$ 0,00" id="est"/></h4>
<h4>Adiantamento a Fornecedores<input type="text" placeholder="R$ 0,00" id="af"/></h4>
<h4>Despesas antecipadas<input type="text" placeholder="R$ 0,00" id="da"/></h4>
</div>
Those sums in
$crTot
will not work well if what is written in the boxes follows the formatR$ X,XX
– Isac
Bruce, please read the [Ask] guide as soon as possible. I opened a meta debate to discuss the case of your other question, as it was not clear but was answered.
– Woss
This page is to bring correct results ? But what is your script before this page, which brings "send" the data in POST ? Or actually, you would have to use GET if you bring in the URL
– rbz
Can you please detail the error? What message does it give? what comes in return...
– Leo Nogueira
Basically, I am creating a user way by entering the values inside the inputs (ncr11 until ncr44) it returns the sum of these inside the input (ncr). The problem is that when I load the page and enter test values within the mentioned inputs, the "ncr" input is empty... When I use if (isset($_POST){...} the page returns Notice: Undefined index: ncr11 in C: xampp htdocs menuVertical apCirculantes.php on line 20 Notice: Undefined index: ncr22 in C: xampp htdocs menuVertical apCirculantes.php on line 21
– Bruce Duarte
The
action
of your form is not being pointed to any page. Or you are making the submission viaJQuery
?– Roberto de Campos
It was being pointed to the page calculos.php, but was instructed to bring the code to before the form, by testing. That way, I left the null action
– Bruce Duarte
Bruce, do you want the result to appear in real time or just when a button is pressed?
– Woss
In real time, that’s the idea.
– Bruce Duarte
I’ll take the liberty of editing your question again so it doesn’t occur like the other one. See how the issue will look and take as a basis for your future questions.
– Woss
Okay Anderson, anything to help will be welcome. Thank you
– Bruce Duarte