Javascript Arrays. Pushing a calculated value to an array returns undefined -


I have created a form for which the numerical values ​​to be entered in that number are then calculated. And comes in some other form. Calculation output should be later added to an array for reference in the session.

All data in the process order function is successfully pushed to its respective arrays, but once I try to push any data that is computed instead of just input, there is no undefined function Not returned.

Any help has been greatly appreciated.

HTML

  & lt; Form & gt; & Lt; Fieldset & gt; Units: & lt; Input type = "number" value = "" id = "formUnits" & gt; ChemS: & lt; Input type = "number" value = "" id = "form kms" & gt; & Lt; Input type = button value = 'submit order' onClick = 'calculate ()' & gt; & Lt; / Fieldset & gt; & Lt; / Form & gt; & Lt; Form & gt; & Lt; Fieldset & gt; Cost per unit: & lt; Input type = "number" id = "perUnitCost" & gt; Delivery Charge: & lt; Input type = "number" id = "delivery charge" & gt; Prior tax: & lt; Input type = "number" id = "pretextual" & gt; & Lt; / Fieldset & gt; & Lt; / Form & gt;  

javascript

  var units = new arrays (); Var kms = new array (); Var timestamp = new array (); Var unitCost = new array (); Var Delivery = New Array (); Var pretex = new array (); Function calculation () {var units = document. GetElementById ("formUnits") value; Var KMS = Document. GetElementById ("formKms"). value; If (km> = 1 & amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; ;; = 20) {distribution = 20} var preTax = unitCost + distribution; Document.getElementById ("perUnitCost"). Value = unitCost.toFixed (2); Document.getElementById ("Delivery Charge"). Value = distribution; Document.getElementById ("pretextual"). Value = preTax.toFixed (2); Process order ()} function process order () {units.push (document.getElementById ('formUnits'). Value); Document.getElementById ('formUnits') value = ''. Kms.push (document.getElementById ('formKms') value.); Document.getElementById ('formKms') value = ''. . TimeStamp.push (date ()) value; Add_calcs_to_array ()} function add_calcs_to_array () {unitCost.push (document.getElementById ('perUnitCost'). Value); . Document.getElementById ('perUnitCost') value = ''; Delivery.push (document.getElementById ('deliveryCharge') value.); . Document.getElementById ('deliveryCharge') value = ''; PreTax.push (document.getElementById ('preTaxTotal').); . Document.getElementById ('preTaxTotal') value = ''; }   

I see your variable started in count as var Should be globals of the globe such as:

  // This is a global variable Var Unitcast = []; Function calculation (units) {// Verizon Unicost Here the global unit cost variable is enigmatic // This means that the unitcast is local for functions. Var unitCost = 0; If (units) {unitCost = units * 11.1; }} Calculation (2); Console.log (unitCost); // still []. Without the calculation without the var, it would be 22.2.  

Comments

Popular posts from this blog

apache - 504 Gateway Time-out The server didn't respond in time. How to fix it? -

c# - .net WebSocket: CloseOutputAsync vs CloseAsync -

c++ - How to properly scale qgroupbox title with stylesheet for high resolution display? -