Here’s an example:
index.html
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Decimal to Octal Converter</title> </head> <body> <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> <script> 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; } </script> </body> </html>
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.