More elegant solution needed for repetitive variable use in Javascript-see answer for explanation (tech difficulties with site)
function calculate(){ var targetModifier1=document.getElementById("tm1").value var obstruction1=0 switch(document.getElementById("obst1").value{ case ("Light Trees"): obstruction1=1; break; case ("Heavy Trees"): obstruction1=2; break; default: obstruction1=0; } var other1=0 switch(document.getElementById("other1").value{ case("jumped"): other1=1; break; case("prone"): other1=2; break; } var targetModifier2=document.getElementById("tm2").value var obstruction2=0 switch(document.getElementById("obst2").value{ case ("Light Trees"): obstruction2=1; break; case ("Heavy Trees"): obstruction2=2; break; default: obstruction2=0; } var other2=0 switch(document.getElementById("other2").value{ case("jumped"): other2=1; break; case("prone"): other2=2; break; } var targetModifier3=document.getElementById("tm3").value var obstruction3=0 switch(document.getElementById("obst3").value{ case ("Light Trees"): obstruction3=1; break; case ("Heavy Trees"): obstruction3=2; break; default: obstruction3=0; } var other3=0 switch(document.getElementById("other3").value{ case("jumped"): other3=1; break; case("prone"): other3=2; break; } var targetModifier4=document.getElementById("tm4").value var obstruction4=0 switch(document.getElementById("obst4").value{ case ("Light Trees"): obstruction4=1; break; case ("Heavy Trees"): obstruction4=2; break; default: obstruction4=0; } var other4=0 switch(document.getElementById("other4").value{ case("jumped"): other4=1; break; case("prone"): other4=2; break; } var toHit1=tm1+obst1+other1; var toHit2=tm2+obst2+other2; var toHit3=tm3+obst3+other3; var toHit4=tm4+obst4+other4; }