-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
41 lines (36 loc) · 1.29 KB
/
script.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
function validateForm() {
var urlInput = document.getElementById("longUrlInput");
var errorSpan = document.getElementById("urlError");
var urlPattern = /^(ftp|http|https):\/\/[^ "]+$/;
if (!urlPattern.test(urlInput.value)) {
errorSpan.textContent = "Invalid URL format. Please enter a valid URL.";
return false;
}
errorSpan.textContent = "";
return true;
}
function copyToClipboard() {
var shortenedUrlInput = document.getElementById("shortenedUrlInput");
shortenedUrlInput.select();
document.execCommand("copy");
}
document.getElementById("shortenForm").addEventListener("submit", function(event) {
event.preventDefault();
var form = this;
var formData = new FormData(form);
fetch(form.action, {
method: form.method,
body: formData
})
.then(response => response.text())
.then(data => {
console.log("Received shortened URL:", data); // Log the received data for debugging
var shortenedUrlInput = document.getElementById("shortenedUrlInput");
shortenedUrlInput.value = data;
var shortenedUrlContainer = document.getElementById("shortenedUrlContainer");
shortenedUrlContainer.style.display = "block";
})
.catch(error => {
console.error('Error:', error);
});
});