if(document.getElementById("applicable_us_sales05").value !== ""){
var applicable_us_sales05 = eval(document.getElementById("applicable_us_sales05").value);
} else {
var applicable_us_sales05 = 0;
}
Is there a shorter way to write that?
if(document.getElementById("applicable_us_sales05").value !== ""){
var applicable_us_sales05 = eval(document.getElementById("applicable_us_sales05").value);
} else {
var applicable_us_sales05 = 0;
}
Is there a shorter way to write that?
You could spend a line declaring a short variable name = to that element.
var sale = document.getElementById("applicable_us_sales05");
if (sale.value !== "") {
var appUsSale05 = eval(sale.value);
} else {
var appUsSale05 = 0;
}
Is there really Javascript in the value of a form element? That seems weird.
I’m sure there’s a faster way to run that, without eval() which, if I read about it correctly, runs slower than just grabbing a string.
var v = parseFloat(document.getElementById("applicable_us_sales05").value);
var applicable_us_sales05 = isNan(v) ? 0 : v;
I wouldn’t use eval()
, since it’s evil and a huge security risk when applied to user-supplied content.
Ooh… another one for my scratchpad.