PIbd-23_Sergunov_M.A._IP/MainPage/LogForMainPage.js

53 lines
1.5 KiB
JavaScript
Raw Permalink Normal View History

2023-04-11 11:14:56 +04:00
const operateButton = document.getElementById("operate");
2023-05-01 23:02:20 +04:00
const operateStringButton = document.getElementById("operateString");
2023-04-11 11:14:56 +04:00
const val1 = document.getElementById("val1");
const val2 = document.getElementById("val2");
const select = document.getElementById("operation");
const finish = document.getElementById("finish");
2023-05-01 23:02:20 +04:00
const operateFButton = document.getElementById("operateF");
const operateFStringButton = document.getElementById("operateFString");
const float1 = document.getElementById("float1");
const float2 = document.getElementById("float2");
const selectF = document.getElementById("operationF");
const finishF = document.getElementById("finishF");
2023-04-11 11:14:56 +04:00
operateButton.onclick=function(){
2023-05-01 23:02:20 +04:00
operate("number");
2023-04-11 11:14:56 +04:00
};
2023-05-01 23:02:20 +04:00
operateStringButton.onclick=function(){
operate("string");
}
operateFButton.onclick=function(){
operate("numberF");
};
function operate(param){
2023-04-11 11:14:56 +04:00
switch(parseInt(select.value)){
case 1:
2023-05-01 23:02:20 +04:00
doOperation("calc1", param)
2023-04-11 11:14:56 +04:00
break;
case 2:
2023-05-01 23:02:20 +04:00
doOperation("calc2", param)
2023-04-11 11:14:56 +04:00
break;
case 3:
2023-05-01 23:02:20 +04:00
doOperation("calc3", param)
2023-04-11 11:14:56 +04:00
break;
case 4:
2023-05-01 23:02:20 +04:00
doOperation("calc4", param)
2023-04-11 11:14:56 +04:00
break;
};
}
2023-05-01 23:02:20 +04:00
2023-04-11 11:14:56 +04:00
function checkNumber(res){
2023-05-01 23:02:20 +04:00
return res;
2023-04-11 11:14:56 +04:00
}
2023-05-01 23:02:20 +04:00
function doOperation(address, type){
console.log("Тип переменных: " + type)
fetch(`http://localhost:8080/${address}?val1=${val1.value}&val2=${val2.value}&type=${type}`)
.then(response => response.text())
.then(res=>finish.innerHTML=checkNumber(res));
2023-04-11 11:14:56 +04:00
}