I made a statement in the options. However, some options that I don’t show in the text
statement will appear undefined
Instead of displaying the word undefined
, I want to replace it with a text message.
Here’s my code below:
function idenmalaria() {
var a, b, c, d, text;
a = document.getElementById("rbc_size").value;
b = document.getElementById("rbc_dis").value;
c = document.getElementById("dot").value;
d = document.getElementById("distribusi").value;
if (a == 1 && b == 1 && c == 1 && d == 1) {
text = "Plasmodium falciparum";
} else if (a == 1 && b == 2 && c == 3 && d == 2) {
text = "Plasmodium malariae";
} else if (a == 2 && b == 1 && c == 2 && d == 2) {
text = "Plasmodium vivax";
} else if (a == 2 && b == 2 && c == 2 && d == 2) {
text = "Plasmodium ovale";
}
document.getElementById("result").value = text;
}
HTML code :
<select id="rbc_size">
<option value="1">RBC normal</option>
<option value="2">RBC big</option>
</select>
<select id="rbc_dis">
<option value="1">RBC distorted</option>
<option value="2">RBC undistorted</option>
</select>
<select id="dot">
<option value="1">Maurer dots</option>
<option value="2">Schüffner dots</option>
<option value="3">None</option>
</select>
<select id="distribusi">
<option value="1">Homogeneous</option>
<option value="2">Heterogeneous</option>
</select>
<button onclick="idenmalaria()" type="submit">Parasit</button>
<input type="text" id="result" />
Any help would be appreciated. Thank you.