<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Kalkulator pH</title>
<style>
body {
font-family: Arial, sans-serif;
margin: 20px;
background-color: #f9f9f9;
color: #333;
}
.product {
margin: 10px 0;
}
.selected {
background-color: #d4edda;
border: 1px solid #28a745;
padding: 10px;
border-radius: 5px;
}
.form-group {
margin: 10px 0;
}
label {
display: block;
margin-bottom: 5px;
font-weight: bold;
}
input, select, button {
padding: 10px;
width: 100%;
box-sizing: border-box;
margin-bottom: 10px;
border: 1px solid #ccc;
border-radius: 4px;
font-size: 1rem;
}
button {
background-color: #007bff;
color: white;
border: none;
cursor: pointer;
transition: background-color 0.3s;
}
button:hover {
background-color: #0056b3;
}
#result {
margin-top: 20px;
padding: 15px;
background-color: #e9ecef;
border-left: 5px solid #007bff;
font-size: 1.1rem;
}
#result.error {
border-left-color: #dc3545;
background-color: #f8d7da;
color: #721c24;
}
</style>
</head>
<body>
<h1>Kalkulator pH</h1>
<div class="form-group">
<label for="product">Wybierz produkt:</label>
<select id="product">
<option value="koh5">Wodorotlenek potasu 5% (KOH)</option>
<option value="hcl17">Kwas chlorowodorowy 17% (m/m)</option>
<option value="hno33">Kwas azotowy 3% (HNO3)</option>
<option value="h3po459">Kwas fosforowy 59% (H3PO4)</option>
<option value="h3po410">Kwas fosforowy 10% (H3PO4)</option>
<option value="k2co3">Węglan potasu (K2CO3)</option>
<option value="koh20">Wodorotlenek potasu 20% (KOH)</option>
</select>
</div>
<div class="form-group">
<label for="volume">Ilość roztworu (w litrach):</label>
<input type="number" id="volume" step="0.01" placeholder="Podaj ilość w litrach">
</div>
<div class="form-group">
<label for="currentPh">Obecne pH:</label>
<input type="number" id="currentPh" step="0.1" placeholder="Podaj obecne pH">
</div>
<div class="form-group">
<label for="targetPh">Docelowe pH:</label>
<input type="number" id="targetPh" step="0.1" placeholder="Podaj docelowe pH">
</div>
<div class="form-group">
<label for="mixPh1">pH pierwszego roztworu:</label>
<input type="number" id="mixPh1" step="0.1" placeholder="Podaj pH pierwszego roztworu">
</div>
<div class="form-group">
<label for="mixVol1">Objętość pierwszego roztworu (w litrach):</label>
<input type="number" id="mixVol1" step="0.01" placeholder="Podaj objętość pierwszego roztworu">
</div>
<div class="form-group">
<label for="mixPh2">pH drugiego roztworu:</label>
<input type="number" id="mixPh2" step="0.1" placeholder="Podaj pH drugiego roztworu">
</div>
<div class="form-group">
<label for="mixVol2">Objętość drugiego roztworu (w litrach):</label>
<input type="number" id="mixVol2" step="0.01" placeholder="Podaj objętość drugiego roztworu">
</div>
<button onclick="calculateMixPh()">Oblicz pH mieszaniny</button>
<button onclick="calculate()">Oblicz ilość</button>
<div id="result"></div>
<script>
function calculate() {
const product = document.getElementById('product').value;
const volume = parseFloat(document.getElementById('volume').value);
const currentPh = parseFloat(document.getElementById('currentPh').value);
const targetPh = parseFloat(document.getElementById('targetPh').value);
if (isNaN(volume) || isNaN(currentPh) || isNaN(targetPh)) {
const result = document.getElementById('result');
result.className = 'error';
result.innerText = "Wprowadź wszystkie wartości.";
return;
}
const concentrationMap = {
koh5: 0.0005,
hcl17: 0.0017,
hno33: 0.0003,
h3po459: 0.0059,
h3po410: 0.0010,
k2co3: 0.001, // przybliżona wartość
koh20: 0.0020
};
const concentration = concentrationMap[product];
const pHChange = targetPh - currentPh;
// Logarytmiczne obliczenia
const HChange = Math.pow(10, -targetPh) - Math.pow(10, -currentPh);
const volumeNeeded = (Math.abs(HChange) * volume) / concentration;
const result = document.getElementById('result');
result.className = '';
result.innerText = `Musisz dodać ${volumeNeeded.toFixed(2)} ml produktu ${document.querySelector(`#product option[value='${product}']`).innerText} na litr.`;
}
function calculateMixPh() {
const mixPh1 = parseFloat(document.getElementById('mixPh1').value);
const mixVol1 = parseFloat(document.getElementById('mixVol1').value);
const mixPh2 = parseFloat(document.getElementById('mixPh2').value);
const mixVol2 = parseFloat(document.getElementById('mixVol2').value);
if (isNaN(mixPh1) || isNaN(mixVol1) || isNaN(mixPh2) || isNaN(mixVol2)) {
const result = document.getElementById('result');
result.className = 'error';
result.innerText = "Wprowadź wszystkie wartości dla mieszaniny.";
return;
}
const totalVolume = mixVol1 + mixVol2;
const totalHPlus = (Math.pow(10, -mixPh1) * mixVol1 + Math.pow(10, -mixPh2) * mixVol2) / totalVolume;
const resultingPh = -Math.log10(totalHPlus);
const result = document.getElementById('result');
result.className = '';
result.innerText = `pH mieszaniny wynosi ${resultingPh.toFixed(2)}.`;
}
</script>
</body>
</html>
Polski
