Can anyone tell me how to add these variables:
var preciopag = Document valores.T1.value; Var libraz = document.valores.T2.value; Var ServicesOcom = 5.00 var contador1 = 0; Var contador2 = 0; Var tramite = 0; Var angioptis = 0; Var ITBMS = 0; Var Total = Presoep + ServicioCom + NVPT + Tramite + ITBMS;
Thanks in advance.
values
elements always had a string , Therefore, +
will result in concatenation , not except that
String number to get value:
var preciopag = + document.valores.T1.value; Var libras = + document.valores.T2.value;
I used +
, which will look at the whole string, but you can see the parseFloat
which will ignore anything Lastly invalid; It is entirely dependent on what you want to do with semi-valid input.
Display:
var preciopag = "5"; // Simulate the document. Original. T. 1.value var libras = "10"; // Simulate the document. Differentiation. 2.value var serviciocom = 5.00 var contador1 = 0; Var contador2 = 0; Var tramite = 0; Var angioptis = 0; Var ITBMS = 0; Var Total = Presoep + ServicioCom + NVPT + Tramite + ITBMS; Snippet.log (total); // "55000" - wrong // instead: preciopag = + "5"; // Simulate the document. Original. T. 1.value libras = + "10"; // Simulate the document. Differentiation. 2.value total = presoepag + servercom.c + angiopet + tramite + ITbms; Snippet.log (total); // "10" - Correct
& lt ;! - Script provides `snippet` object, see Http://meta.stackexchange.com/a/242144/134069 - & gt; & Lt; Script src = "http://tjcrowder.github.io/simple-snippets-console/snippet.js" & gt; & Lt; / Script & gt;
No comments:
Post a Comment