-1
I am trying to make a function that returns the result of an expression. Example:
I want to make the distribution of a value informed by the months of a year. Example:
120,000 = Jan/10,000 Feb/10,000 etc.
However, if the user changes any month to more or less, the result of the reported value (120,000) subtracted from the sum of the months must appear in the month of December.
With the help of my friend Darlei,
function saldo()
{
var total = document.getElementById("total");
var jan = document.getElementById("jan");
var fev = document.getElementById("fev");
var mar = document.getElementById("mar");
var abr = document.getElementById("abr");
var mai = document.getElementById("mai");
var jun = document.getElementById("jun");
var jul = document.getElementById("jul");
var ago = document.getElementById("ago");
var set = document.getElementById("set");
var out = document.getElementById("out");
var nov = document.getElementById("nov");
var dez = document.getElementById("dez");
dez.value = total.value - jan.value - fev.value - mar.value - abr.value - mai.value - jun.value - jul.value - ago.value - set.value - out.value - nov.value;
}
<form id="form1" name="form1" method="post" action="">
<p> </p>
<p>
<label for="total">Total</label>
<input type="text" name="total" id="total" value="120.000" />
<label for="jan">Jan</label>
<input type="text" name="jan" id="jan" />
<label for="textfield">Fev</label>
<input type="text" name="fev" id="fev" />
<label for="textfield">Mar</label>
<input type="text" name="mar" id="mar" />
<label for="textfield">Abr</label>
<input type="text" name="abr" id="abr" />
<label for="textfield">Mai</label>
<input type="text" name="mai" id="mai" />
<label for="textfield">Jun</label>
<input type="text" name="jun" id="jun" />
<label for="textfield">Jul</label>
<input type="text" name="jul" id="jul" />
<label for="textfield">Ago</label>
<input type="text" name="ago" id="ago" />
<label for="textfield">Set</label>
<input type="text" name="set" id="set" />
<label for="textfield">Out</label>
<input type="text" name="out" id="out" />
<label for="textfield">Nov</label>
<input type="text" name="nov" id="nov" />
<label for="textfield">Dez</label>
<input type="text" name="dez" id="dez" />
</p>
</form>
But I still don’t know how to return this value to INPUT
Do you have all values in inputs? How are they loaded/inserted into the page? If you are only going to do/show the calculation, you could do a simpler js, ajax only if you need to save the values in the database or return some value from there, that would be the case?
– Darlei Fernando Zillmer
Do not need to save these values no. They come from a form and will be displayed after inserting in the database. How can I do this?
– Webster Moitinho
If the user increases the value of a month, the subtraction will be negative because the sum of the months will be greater than 120,000
– Sam
That’s exactly what, I’d like to point out. Hypo-sufficiency and hyper-sufficiency
– Webster Moitinho