IP_Ismailov_Pibd-22/front/js/script.js

36 lines
1021 B
JavaScript
Raw Permalink Normal View History

2023-03-06 15:16:40 +04:00
let form = document.getElementById("form");
let info = document.getElementById("res");
2023-04-02 23:49:02 +04:00
let typeInput = document.getElementById("type");
2023-03-06 15:16:40 +04:00
form.onsubmit = async (e) => {
e.preventDefault();
if(form.num1.value === "") return;
if(form.num2.value === "") return;
let index = form.selected.selectedIndex;
let op = form.selected.options[index].textContent;
let res = "";
function chooseOperation(oper){
switch(oper){
2023-04-02 23:49:02 +04:00
case "Сложение":
2023-03-06 15:16:40 +04:00
return "sum"
2023-04-02 23:49:02 +04:00
case "Вычитание":
return "minus"
case "Переворачивание":
return "reverse"
case "Сравнение":
return "comparison"
2023-03-06 15:16:40 +04:00
}
}
2023-04-02 23:49:02 +04:00
let type = typeInput.value;
2023-03-06 15:16:40 +04:00
let operstor = chooseOperation(op)
2023-04-02 23:49:02 +04:00
if(form.num2.value == 0)
return;
res = await fetch(`http://localhost:8080/${operstor}?first=${form.num1.value}&second=${form.num2.value }&type=${type}`)
2023-03-06 15:16:40 +04:00
2023-04-02 23:49:02 +04:00
res = await res.text();
2023-03-06 15:16:40 +04:00
form.res.value = res;
}