42 lines
1.4 KiB
JavaScript
42 lines
1.4 KiB
JavaScript
document.addEventListener('DOMContentLoaded', function() {
|
|
var forms = document.querySelectorAll('.needs-validation');
|
|
|
|
Array.from(forms).forEach(form => {
|
|
form.addEventListener('submit', event => {
|
|
if (!form.checkValidity()) {
|
|
event.preventDefault();
|
|
event.stopPropagation();
|
|
}
|
|
|
|
form.classList.add('was-validated');
|
|
}, false);
|
|
});
|
|
});
|
|
|
|
document.getElementsByClassName("needs-validation")[0].addEventListener('submit', async function(event) {
|
|
event.preventDefault();
|
|
url = "http://localhost:8080/"
|
|
if (document.getElementById("radioPlus").checked) {
|
|
url += "plus"
|
|
}
|
|
if (document.getElementById("radioMinus").checked) {
|
|
url += "minus"
|
|
}
|
|
if (document.getElementById("radioMultiply").checked) {
|
|
url += "multiply"
|
|
}
|
|
if (document.getElementById("radioDivide").checked) {
|
|
url += "divide"
|
|
}
|
|
if (url == "http://localhost:8080/") {
|
|
document.getElementById("result").innerHTML = "Выберите действие!"
|
|
return
|
|
}
|
|
url += "?value1=" + document.getElementById("input1").value + "&value2=" + document.getElementById("input2").value + "&type=" + document.getElementById("selectType").value
|
|
document.getElementById("result").innerHTML = await performFetch(url)
|
|
});
|
|
|
|
async function performFetch(url) {
|
|
let resp = await fetch(url)
|
|
return await resp.text()
|
|
} |