# How to Convert Hexadecimal to Decimal Using JavaScript?

Through this tutorial you can easily convert the value of hexa to decimal through javascript. You are also explained as an example below.

Convert Hexa to Decimal Using JS and fetch value in html, hexa to decimal canvert by javascript or jquery

You can easily convert hexa to decimal by javascript and also show its value in the html page by id. You have a well explained below how you can convert hexa decimal to decimal by javascript You can show it in html page by converting id.

```<script>
function hexToDec(hex) {
var result = 0, digitValue;
hex = hex.toLowerCase();
for (var i = 0; i < hex.length; i++) {
digitValue = '0123456789abcdefgh'.indexOf(hex[i]);
result = result * 16 + digitValue;
}
return result;
}
function Calculate() {
var x = document.getElementById("myText").value;
document.getElementById("demo").innerHTML = hexToDec(x);
}
</script>```

Below you are given the complete code of html and javascript.You copy this code and make an html file in your computer and paste this code. Then after that run this code on your browser.

hexa-to-decimal-converter.html

```<!DOCTYPE html>
<html>
<title>Create Hexa Decimal Value Convert into Decimal Value Using JavaScript?</title>
<body>
<div class="controls">
<div class="row">
<form name="form1">
<div class="col-md-12">
<div class="form-group">
<label for="form_name">Hexa Decimal Value Convert into Decimal Value:- *</label>
<input type="text" id="myText" class="form-control">
</div>
</div>
<div class="col-md-12">
<button type="button" value="Calculate" onclick="Calculate()" class="btn btn-success btn-send">Calculate</button>
</div>
<div class="col-md-12">
<p id="demo"></p>
</div>
</form>
</div>
</div>
<script>
function hexToDec(hex) {
var result = 0, digitValue;
hex = hex.toLowerCase();
for (var i = 0; i < hex.length; i++) {
digitValue = '0123456789abcdefgh'.indexOf(hex[i]);
result = result * 16 + digitValue;
}
return result;
}
function Calculate() {
var x = document.getElementById("myText").value;
document.getElementById("demo").innerHTML = hexToDec(x);
}
</script>
</body>
</html>```