How to Convert Text to ASCII Using JavaScript With HTML?

Hello Friends Today, through this tutorial, I will tell you How to Text to ASCII Convert Using JavaScript Without Submit Button with HTML? You can create a simple Text to ASCII converter using JavaScript without a submit button with HTML. The conversion can occur dynamically as the user types. 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>Text to ASCII Converter</title>
<style>
body {
font-family: Arial, sans-serif;
margin: 20px;
}
label {
display: block;
margin-bottom: 8px;
}
textarea {
width: 100%;
height: 100px;
padding: 8px;
margin-bottom: 16px;
box-sizing: border-box;
}
p {
font-weight: bold;
}
</style>
</head>
<body>
<h2>Text to ASCII Converter</h2>
<label for="textInput">Enter Text:</label>
<textarea id="textInput" placeholder="Type your text here" oninput="convertTextToASCII()"></textarea>

<p id="asciiResult"></p>

<script>
function convertTextToASCII() {

// Get the text input value
const textInput = document.getElementById('textInput').value;

// Convert each character to ASCII
const asciiArray = Array.from(textInput).map(char => char.charCodeAt(0));

// Display the result
document.getElementById('asciiResult').innerText = `ASCII: ${asciiArray.join(', ')}`;
}
</script>
</body>
</html>

In this example, the `convertTextToASCII` function is called whenever the user types in the textarea (`oninput` event). The function retrieves the input text, converts each character to its ASCII code using `char.charCodeAt(0)`, and displays the result in a paragraph below the textarea. The conversion happens dynamically as the user types.