-
Notifications
You must be signed in to change notification settings - Fork 0
/
riskcalc.js
38 lines (33 loc) · 1.33 KB
/
riskcalc.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
M.AutoInit();
let resultTobacco = 0.0;
let resultAlc = 0.0;
function calcTobacco(value, rr){
resultTobacco = 0.0;
let inputs = document.getElementsByClassName("tobacco");
for (i=0; i<inputs.length;i++){
if (inputs[i].checked){
resultTobacco+=parseFloat(inputs[i].dataset.rr);
}
}
document.getElementById("tobaccoResult").innerHTML="Tobacco induced risk for oral cancer: "+resultTobacco.toFixed(2);
checkCombined();
}
function calcAlcohol(){
resultAlc = 0.0;
let inputs = document.getElementsByClassName("alcohol");
for (i=0; i<inputs.length;i++){
if (inputs[i].checked){
resultAlc = parseFloat(inputs[i].dataset.oral);
document.getElementById("oral").innerHTML="Oral and pharyngeal cancer: "+parseFloat(inputs[i].dataset.oral)
document.getElementById("laryngeal").innerHTML="Laryngeal cancer: "+parseFloat(inputs[i].dataset.laryngeal)
document.getElementById("esophageal").innerHTML="Esophageal cancer: "+parseFloat(inputs[i].dataset.esophageal)
document.getElementById("liver").innerHTML="Liver cancer: "+parseFloat(inputs[i].dataset.liver)
}
}
checkCombined();
}
function checkCombined(){
if (resultTobacco > 0 && resultAlc > 0){
document.getElementById("oral").innerHTML="Oral and pharyngeal cancer: \nCombined risk of "+resultAlc+" x "+resultTobacco.toFixed(2)+" = "+(resultAlc*resultTobacco).toFixed(2);
}
}