I'm very new to programming and am trying to write an application for a decimal to hexadecimal converter. When you type a number into a number box (in base 10) and you see the base-16 equivalent appearing as the value in the box change. I cannot figure out how to make my program run. Any suggestions would be greatly appreciated! HTML:
Base Ten:
<input type="number" id="base10" onkeydown="convertBase10to16()">
<br>Base Sixteen:
<input id='base16'>
Javascript:
var base10 =
document.getElementById("base10");
var base16 =
document.getElementById("base16");
var convertBase10to16() = {function () {
if (id("base10").value !== '')
{id("base16").value = parseInt(id("base10").value,10).toString(16);}
};
Your code have several syntax errors. Here is what it should look like
var base10 = document.getElementById("base10");
var base16 = document.getElementById("base16");
base10.addEventListener("blur", function() {
var num = Number(this.value);
base16.value = num.toString(16);
});
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.