I run a site/forum for Diabetes help. We’ve developed a Calculators block that helps convert Blood Sugar readings from one unit to another.
[CODE]<!DOCTYPE html>
<html>
<head>
<meta charset=”UTF-8″>
<title>Diabetes Calculators</title>
<style>
p, label {
font-weight: normal;
display: block;
}
.sugar {
color: #00557F;
}
.a1c {
color: #AE0B1B;
}
.temperature {
color: #BA3114;
}
</style>
</head>
<body>
<div class=”sugar”>
<p>Blood Sugar</p>
<label><input id=”c” onkeyup=”convert(this,f)”size=”8″> mmol/l</label>
equals
<label><input id=”f” onkeyup=”convert(this,c)”size=”8″> mg/dl</label>
</div>
<div class=”a1c”>
<p>A1c to Avg. BG</p>
<label><input id=”a” onkeyup=”convert(this,s)” size=”8″> A1c</label>
equals
<label><input id=”s” onkeyup=”convert(this,a)”size=”8″> Est Avg BG</label>
</div>
<div class=”temperature”>
<p>Temperature</p>
<label><input id=”x” onkeyup=”convert(this,y)”size=”8″> <sup>o</sup> C</label>
equals
<label><input id=”y” onkeyup=”convert(this,x)”size=”8″> <sup>o</sup> F</label>
</div>
<script>
function convert(el,answer) {
switch (el.id) {
case ‘c’:
answer.value = (el.value * 18.05).toFixed(2);
break;
case ‘f’:
answer.value = (el.value / 18.05).toFixed(2);
break;
case ‘a’:
answer.value = ((el.value * 35.6) – 77.3).toFixed(2);
break;
case ‘s’:
answer.value = (((el.value * 1) + 77.3) / 35.6).toFixed(2);
break;
case ‘x’:
answer.value = ((el.value * 1.8) + 32) .toFixed(2);
break;
case ‘y’ :
answer.value = (((el.value * 1) -32) / 1.8) .toFixed(2);
break;
}
}
</script>
</body>
</html>
The top 2 calculators work fine (when only the 2 are used)
As soon as the Temperature calculator is added all of them stop working. What am I doing wrong ?