Minhasapov_Network_Programming/frontend/index.html

64 lines
2.9 KiB
HTML

<!DOCTYPE html>
<html>
<head>
<title>Calc</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="val1">
</div>
<div class="col">
<select id="operation">
<option value="sum" selected>+</option>
<option value="sub">-</option>
<option value="mul">*</option>
<option value="div">/</option>
</select>
</div>
<div class="col">
<input type="text" id="val2">
</div>
</div>
<div class="row">
<div class="col">
<button type="button" id="get-int-result" onclick="calculate('inttype')">Result for int</button>
</div>
<div class="col is-right">
<button type="button" id="get-string-result" onclick="calculate('stringtype')">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(resulttype) {
const val1 = document.getElementById("val1").value
const val2 = document.getElementById("val2").value
const op = document.getElementById("operation").value
if (op == 'sum') {
document.getElementById("result").innerHTML = await (await fetch(`http://127.0.0.1:8080/sum?val1=${val1}&val2=${val2}&type=${resulttype}`)).text()
} else if (op == 'sub') {
document.getElementById("result").innerHTML = await (await fetch(`http://127.0.0.1:8080/sub?val1=${val1}&val2=${val2}&type=${resulttype}`)).text()
} else if (op == 'mul') {
document.getElementById("result").innerHTML = await (await fetch(`http://127.0.0.1:8080/mul?val1=${val1}&val2=${val2}&type=${resulttype}`)).text()
} else {
document.getElementById("result").innerHTML = await (await fetch(`http://127.0.0.1:8080/div?val1=${val1}&val2=${val2}&type=${resulttype}`)).text()
}
}
</script>
</body>
</html>