Hello Friends Today, through this tutorial, I will tell you How to Decimal to ASCII Converter Tool Create Using JavaScript With HTML? Here’s the HTML and JavaScript code you can use to convert a decimal value to its corresponding ASCII character:
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 ASCII Converter</title> </head> <body> <h1>Enter a decimal value:</h1> <input type="number" id="decimalInput"> <button onclick="convert()">Convert</button> <br> <p id="result"></p> <script> function convert() { // Get the decimal value from the input field const decimalValue = document.getElementById("decimalInput").value; // Check if the input is a valid number if (isNaN(decimalValue)) { alert("Please enter a valid number."); return; } // Convert the decimal value to its ASCII character using String.fromCharCode() const asciiChar = String.fromCharCode(decimalValue); // Display the converted character in the result paragraph document.getElementById("result").textContent = `The ASCII character for ${decimalValue} is "${asciiChar}".`; } </script> </body> </html>
Explanation:-
1. The HTML code creates a basic webpage with an input field, a button, and a paragraph to display the results.
2. The JavaScript code defines a function `convert()` that gets called when the button is clicked.
3. Inside the function, we get the decimal value from the input field and check if it’s a valid number using `isNaN()`.
4. If the value is valid, we use the `String.fromCharCode()` method to convert the decimal value to its corresponding ASCII character.
5. Finally, we display the converted character along with the original decimal value in the result paragraph.