36 lines
1021 B
JavaScript
36 lines
1021 B
JavaScript
let form = document.getElementById("form");
|
|
let info = document.getElementById("res");
|
|
let typeInput = document.getElementById("type");
|
|
|
|
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){
|
|
case "Сложение":
|
|
return "sum"
|
|
case "Вычитание":
|
|
return "minus"
|
|
case "Переворачивание":
|
|
return "reverse"
|
|
case "Сравнение":
|
|
return "comparison"
|
|
}
|
|
}
|
|
let type = typeInput.value;
|
|
let operstor = chooseOperation(op)
|
|
if(form.num2.value == 0)
|
|
return;
|
|
res = await fetch(`http://localhost:8080/${operstor}?first=${form.num1.value}&second=${form.num2.value }&type=${type}`)
|
|
|
|
res = await res.text();
|
|
|
|
form.res.value = res;
|
|
} |