javascript - Entering data to a form and returning the data without duplication -
I am trying to create a form in JS which takes less and high urgency and creates the output that looks
Like this graphic:
The problem I am running is that when I submit for a second time, it repeats all this again, so if I enter 30,40 for the first time, and another 60,80 it will be displayed:
< P> 30,4030,40
60,80
The more problems you enter, the more problems the data gets worse.
'strict experiment'; // Output from where reference: var output = document.getElementById ('output'); // Create a new object: var todays_date = new date (); Var day = todays_date.getDate (); Var month = todays_date.getMonth () + 1; Var year = todays_date.getFullYear (); Var temps_data_low = []; Var temps_data_high = []; Var temp_data_msg = ""; Var sum_low = 0; Var sum_high = 0; Temp_data_msg + = "Date" + '' + "Low Temperature" + '' + + "High Temperature" + '& lt; Br> & # 39; & # 39; Function call () {'strict use'; Var low temperature = parflot (document.getalmentbiid ('low temperature'). Value); Var Hightemfter = Perfalto (Document.GateAlmentBiID ('High Temperature'). Value); Console.log (LowTemperature); Console.log (hightemperature); Temps_data_low.push (LowTemperature); Temps_data_high.push (hightemperature); // Update the page: for (var i = 0, count = temps_data_low.length; i ';' Strict use '; Calc (low temperature, high temperature, temp_data_msg, temps_data_low, temps_data_high, sum_low, sum_high);} function calc (low temperature, high temperature, temp_data_msg, temps_data_low, temps_data_high, sum_low, sum_high); Temps_data_low.length === 1) {temp_data_msg + = "average" + low temperature + "" + high temperature + "& lt; Br> & gt; ";} and {temp_data_msg + =" average "+ (sum_low / temps_data_low.length) +" "+ (sum_high / temps_data_high.length) +" & lt; Br>;;;;;; // messsage output.innerHTML; display; temp_data_msg; description is false; // initial setup: function init () {'strict use'; document.getElementById ('theform') .OnSubmit = Call;} // init () Function Finish Window.onload = init;
You never reset your temp_data_msg
variable.
So each time there is a form submission, all of you are adding the same data to the previous output.
You can fix it by adding temp_data_msg = ';
simply call
f Function:
function call () {// omitted ... temps_data_low.push (lower temperature) before your loop <; temps_data_high.push (hightemperature); Temp_data_msg = ''; // Update for this line // page: var (i = 0, count = temps_data_low.length; i & lt; count; i ++) {// omitted. ..
This will have side effects of your titles being deleted, so at the top of the script where you declared temp_data_msg
.
var temp_data_header = "date" + '' + "low temperature" + "+" high temperature "+ '& lt; Br> & # 39; & # 39;
Then when you produce the last lesson:
output.innerHTML = temp_data_header + temp_data_msg;
Comments
Post a Comment