41 lines
1.7 KiB
JavaScript
41 lines
1.7 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 = ""
|
|
if (document.getElementById("radioUppercase").checked) {
|
|
url = "http://localhost:8080/uppercase?value=" + document.getElementById("input").value
|
|
}
|
|
if (document.getElementById("radioLowcase").checked) {
|
|
url = "http://localhost:8080/lowercase?value=" + document.getElementById("input").value
|
|
}
|
|
if (document.getElementById("radioSplit").checked) {
|
|
url = "http://localhost:8080/split?value=" + document.getElementById("input").value + "&splitBy=" + document.getElementById("inputSplitBy").value
|
|
}
|
|
if (document.getElementById("radioReplace").checked) {
|
|
url = "http://localhost:8080/replace?value=" + document.getElementById("input").value + "&old=" + document.getElementById("inputReplaceOld").value + "&new=" + document.getElementById("inputReplaceNew").value
|
|
}
|
|
if (url == "") {
|
|
document.getElementById("result").innerHTML = "Выберите действие!"
|
|
}
|
|
// performFetch(url).then(data => {document.getElementById("result").innerHTML = data})
|
|
document.getElementById("result").innerHTML = await performFetch(url)
|
|
});
|
|
|
|
async function performFetch(url) {
|
|
let resp = await fetch(url)
|
|
return await resp.text()
|
|
} |