I have a form where a user enters a decimal number and then from the dropdown menu he chooses if he wants to convert it either to binary, octal or hexadecimal by clicking on a c
I see some error
it's not getElementbyId ==> is getElementById, bad use of the context(this) ... in your function Answer (this) is pointing to to the button .. I think you need to change the value on the input, right
try this:
function Answer(e) {
e.preventDefault();
var input = document.getElementById('input');
if (document.getElementById('selectid').value ==="binary") {
input.value = Number(input.value).toString(2);
}
else if (document.getElementById('selectid').value ==="octal") {
input.value = Number(input.value).toString(8);
}
else if (document.getElementById('selectid').value ==="hexadecimal") {
input.value = Number(input.value).toString(16);
}
}
Note: add id='input' to the input on the HTML part