<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Text to Decimal</title>
<style>
body {
font-family: Arial, sans-serif;
max-width: 600px;
margin: 50px auto;
padding: 20px;
background: #f5f5f5;
}
.container {
background: white;
padding: 30px;
border-radius: 8px;
box-shadow: 0 2px 10px rgba(0,0,0,0.1);
}
h2 { color: #333; margin-top: 0; }
textarea {
width: 100%;
height: 100px;
padding: 10px;
border: 1px solid #ddd;
border-radius: 4px;
font-size: 16px;
box-sizing: border-box;
}
button {
background: #4CAF50;
color: white;
padding: 12px 24px;
border: none;
border-radius: 4px;
cursor: pointer;
font-size: 16px;
margin: 10px 5px 10px 0;
}
button:hover { background: #45a049; }
#output {
background: #f9f9f9;
padding: 15px;
border-radius: 4px;
min-height: 50px;
word-wrap: break-word;
font-family: monospace;
}
</style>
</head>
<body>
<div class="container">
<h2>Text to Decimal Converter</h2>
<textarea id="inputText" placeholder="Enter text here..."></textarea>
<br>
<button onclick="convertToDecimal()">Convert</button>
<button onclick="clearAll()">Clear</button>
<h3>Decimal Output:</h3>
<div id="output"></div>
</div>
<script>
function convertToDecimal() {
const text = document.getElementById('inputText').value;
let decimal = '';
for (let i = 0; i < text.length; i++) {
decimal += text.charCodeAt(i);
if (i < text.length - 1) decimal += ' ';
}
document.getElementById('output').textContent = decimal || 'Result will appear here';
}
function clearAll() {
document.getElementById('inputText').value = '';
document.getElementById('output').textContent = '';
}
</script>
</body>
</html>
No comments:
Post a Comment