Convert Decimal to Octal Using JavaScript with HTML

Hello Friends Today, through this tutorial, I will tell you How to Decimal to Octal Convert Using Javascript with HTML? You can create a simple HTML page with JavaScript to convert a decimal number to octal.

Here’s an example:


<!DOCTYPE html>
<html lang="en">
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Decimal to Octal Converter</title>
<h1>Decimal to Octal Converter</h1>
<label for="decimalInput">Enter Decimal Number:</label>
<input type="number" id="decimalInput">
<button onclick="convertDecimalToOctal()">Convert</button>
<p id="result"></p>
function convertDecimalToOctal() {
// Get the decimal input value
var decimalInput = document.getElementById("decimalInput").value;
// Convert to octal
var octalResult = (parseInt(decimalInput, 10)).toString(8);
// Display the result
document.getElementById("result").innerHTML = "Octal Equivalent: " + octalResult;

This HTML page includes a form with an input field to enter the decimal number. When you click the “Convert” button, it triggers the `convertDecimalToOctal` function, which takes the input, converts it to octal using `parseInt` and `toString`, and then displays the result on the page.