The JS code is working swell, although it makes some risky assumptions. The problem you have is that you submit the form with that button, so the whole page reloads and you can't see the results.
<form id=convert onsubmit="myfunction(); return false;">
This will force the form not to submit itself and there you go - problem solved!
However i have a few notes about good practices:
- don't use <center> tag in HTML5, as it is not supported anymore: center
- when you are accessing the value of #decimal, it's type is string and then you compare it with a number (0). If you expect a number, you should use:
var x = document.getElementById("decimal").value;
x = parseInt( x, 10 );
which will try to convert it to a decimal integer.
also, converting between number bases could be as simple as:
var x = parseInt( document.getElementById("decimal").value, 10 );
document.getElementById("display").innerHTML = x.toString( 2 );
Read about it here