Polevoy_Network_Programming/frontend/index.html
Katerina881 8315a23855 Lab2
2023-02-21 11:20:02 +04:00

65 lines
2.9 KiB
HTML

<!DOCTYPE html>
<html>
<head>
<title>Calculator</title>
<link rel="stylesheet" href="https://unpkg.com/chota@latest">
</head>
<body>
<div class="container" style="max-width:600px">
<div class="card row is-full-screen is-center">
<div class="col">
<div class="row">
<div class="col">
<input type="text" id="value1">
</div>
<div class="col">
<select id="operation">
<option value="sum" selected>+</option>
<option value="sub">-</option>
<option value="mul">*</option>
<option value="invert">~</option>
</select>
</div>
<div class="col">
<input type="text" id="value2">
</div>
</div>
<div class="row">
<div class="col">
<button type="button" id="get-int-result" onclick="calculate('intops')">Result for int</button>
</div>
<div class="col is-right">
<button type="button" id="get-string-result" onclick="calculate('stringops')">Result for string</button>
</div>
</div>
<div class="card row is-center">
<h5 class="is-center" id="result"></h5>
</div>
</div>
</div>
</div>
<script>
async function calculate(ops) {
const value1 = document.getElementById("value1").value
const value2 = document.getElementById("value2").value
const op = document.getElementById("operation").value
if (op == 'sum') {
document.getElementById("result").innerHTML = await (await fetch(`http://127.0.0.1:8080/sum?value1=${value1}&value2=${value2}&ops=${ops}`)).text()
} else if (op == 'sub') {
document.getElementById("result").innerHTML = await (await fetch(`http://127.0.0.1:8080/sub?value1=${value1}&value2=${value2}&ops=${ops}`)).text()
} else if (op == 'mul') {
document.getElementById("result").innerHTML = await (await fetch(`http://127.0.0.1:8080/mul?value=${value1}&count=${value2}&ops=${ops}`)).text()
} else {
document.getElementById("result").innerHTML = await (await fetch(`http://127.0.0.1:8080/invert?value=${value1}&ops=${ops}`)).text()
}
}
</script>
</body>
</html>