IntProg_Zhimolostnova_A.V./Front/main.js
2023-03-04 12:57:40 +04:00

39 lines
1.3 KiB
JavaScript

async function calculate(){
const valA = document.getElementById("var_a").value
const valB = document.getElementById("var_b").value
const oper = document.getElementById("operation").value
const type = document.getElementById("valueType").value
var url = `http://localhost:8080/${oper}?type=${type}&a=${valA}&b=${valB}`
console.log(url)
const responce = await fetch(url)
const json = await responce.json()
if(json.content.errorCode != null){
document.getElementById("ansver").innerHTML = "Ошибка: "+ json.content.errorMassage;
}
else{
document.getElementById("ansver").innerHTML = "Ответ: "+ json.content
}
}
function changeVariableInputs(){
const oper = document.getElementById("operation").value
if(oper === "len" || oper === "inv"){
document.getElementById("InputFieldB").classList.add("hide")
}
else{
document.getElementById("InputFieldB").classList.remove("hide")
}
}
function changeInputBoxType(){
const type = document.getElementById("valueType").value
if(type === "number"){
document.getElementById("var_a").type = "number"
document.getElementById("var_b").type = "number"
}
else{
document.getElementById("var_a").type = "text"
document.getElementById("var_b").type = "text"
}
}