JSFiddle - React, Tailwind, and code Playground
HTML
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<link rel="stylesheet" href="összeado.css"type="text/css">
<title>Összeadás</title>
<script>
function osszeadas() {
const normalizeValue = (str, value, replace) => String(str).replace(value,replace);
const calc = (val1, val2) => {
const n1 = parseFloat(normalizeValue(val1, ',', '.'));
const n2 = parseFloat(normalizeValue(val2, ',', '.'));
return n2 ?
parseFloat(normalizeValue(val1, ',', '.')) +
parseFloat(normalizeValue(val2, ',', '.')) :
0;
}
const osszeg_input = document.getElementById('osszeg');
const ujszam_input = document.getElementById('ujszam');
const calculated = calc(osszeg_input.value, ujszam_input.value);
osszeg_input.value = calculated ? normalizeValue(calculated, '.', ',') : osszeg_input.value;
ujszam_input.value = '';
}
</script>
</head>
<body>
<style>
.container {
padding: 20px;
}
.custom-input-style input {
height: 40px;
font-size: 20px;
margin: 10px 0;
}
.custom-input-style label {
font-size: 30px;
font-weight: bold;
}
</style>
<div class="container">
<div class="custom-input-style">
<label for='osszeg'>Összeg:</label>
<input id='osszeg' disabled value='0'/>
</div>
<div class="custom-input-style">
<label for='ujszam'>Hozzáadandó:</label>
<input id='ujszam' type="text" pattern="-?[0-9]+([/.,][0-9]+)?">
</div>
<button onclick="osszeadas()">Összeadás</button>
</div>
</body>
</html>