This past school year I graduated from high school and I am now an intern at a small internet marketing company. My current task is to develop an online price estimator so that the salespeople can quickly provide consistent estimates for our services. This is my first Javascript project. The most advanced thing I accomplished in js previously was a just few small and basic dom manipulation tasks.
I found a site that has an estimator almost as robust as I need mine to be. So I am reading their code to figure out how it works so I can make my own version. I was told that it is bad practice to use eval() on user submitted data. So, I would like to know what to replace eval() with in this code.
frm = document.form1;
for (var i = 0; i < document.form1.elements.length; i++) {
if (frm.elements[i].type == 'checkbox' || frm.elements[i].type == 'radio') {
if (frm.elements[i].checked) {
v = eval("frm.val" + frm.elements[i].value);
mult = eval("frm.mult" + frm.elements[i].value);
mult = mult.value;
if (mult == '') {
mult = 1
} else {
mult = parseInt(mult)
}
hrs = hrs + parseInt(v.value) * mult;
var cur_val = frm.elements[i].title;
var make_rfp = cur_val.replace("___", mult);
document.getElementById('quote_des').value += make_rfp + "\n";
}
}
}
Here is the site I pulled this code from: https://www.designquote.net/html/dq_estimate_wizard.cfm