IP_PIbd-21_Eliseev_EE/spring_online_calculator/LabOne/items.js

53 lines
1.5 KiB
JavaScript

const one = document.getElementById('First');
const two = document.getElementById('Second');
const result = document.getElementById('Result');
const check = null;
const button_s = document.getElementById('Sum');
button_s.addEventListener("click", function()
{
console.log("Кнопка нажата.");
fetch('http://localhost:8080/plus?num_1=' + one.value + '&num_2=' + two.value)
.then((response) => response.text())
.then((data) => result.value = data)
});
const button_min = document.getElementById('Minus');
button_min.addEventListener("click", function()
{
console.log("Кнопка нажата.");
fetch('http://localhost:8080/minus?num_1=' + one.value + '&num_2=' + two.value)
.then((response) => response.text())
.then((data) => result.value = data)
});
const button_i = document.getElementById('Implement');
button_i.addEventListener("click", function()
{
console.log("Кнопка нажата.");
if(two.value == 0)
{
result.value = "Error";
}
else
{
fetch('http://localhost:8080/implement?num_1=' + one.value + '&num_2=' + two.value)
.then((response) => response.text())
.then((data) => result.value = data)
}
});
const button_m = document.getElementById('Multiplication');
button_m.addEventListener("click", function()
{
console.log("Кнопка нажата.");
fetch('http://localhost:8080/multiplication?num_1=' + one.value + '&num_2=' + two.value)
.then((response) => response.text())
.then((data) => result.value = data)
});