Minhasapov_Network_Programming/frontend/index.html

64 lines
2.9 KiB
HTML
Raw Normal View History

2023-02-19 19:51:31 +04:00
<!DOCTYPE html>
<html>
<head>
<title>Calc</title>
2023-03-07 00:21:23 +04:00
<link rel="stylesheet" href="https://unpkg.com/chota@latest">
2023-02-19 19:51:31 +04:00
</head>
<body>
2023-03-07 00:21:23 +04:00
<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>
2023-02-19 19:51:31 +04:00
<script>
2023-03-07 00:21:23 +04:00
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()
}
2023-02-19 19:51:31 +04:00
}
</script>
</body>
</html>