-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
101 lines (92 loc) · 2.32 KB
/
index.html
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
<!DOCTYPE html>
<html>
<head>
<title>Submit Form</title>
<style>
body {
font-family: Arial, sans-serif;
background-color: #f5f5f5;
margin: 0;
padding: 0;
}
h1 {
text-align: center;
}
#myForm {
max-width: 400px;
margin: 20px auto;
background-color: #fff;
padding: 20px;
border-radius: 5px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
}
label {
display: block;
margin-bottom: 10px;
}
input[type="text"],
input[type="password"] {
width: 90%;
padding: 10px;
border: 1px solid #ccc;
border-radius: 3px;
font-size: 16px;
margin-bottom: 10px;
}
button[type="submit"] {
background-color: #4CAF50;
color: #fff;
padding: 10px 20px;
border: none;
border-radius: 3px;
font-size: 16px;
cursor: pointer;
display: block;
margin: 0 auto;
}
button[type="submit"]:hover {
background-color: #45a049;
}
</style>
</head>
<body>
<h1>Submit Form</h1>
<form id="myForm">
<label for="user_name">Username:</label>
<input type="text" id="user_name" name="user_name" required><br><br>
<label for="password">Password:</label>
<input type="password" id="password" name="password" required><br><br>
<button type="submit">sign-up</button>
</form>
<script>
// Submit form data
document.getElementById("myForm").addEventListener("submit", function(event) {
event.preventDefault(); // Prevent default form submission
// Retrieve form data
const formData = {
user_name: document.getElementById("user_name").value,
password: parseInt(document.getElementById("password").value)
};
// Send POST request using Fetch API
fetch("http://localhost:8000/", {
method: "POST",
headers: {
"Content-Type": "application/json"
},
body: JSON.stringify(formData)
})
.then(response => response.json())
.then(data => {
console.log(data);
alert("Data submitted successfully!");
// Reset form
document.getElementById("myForm").reset();
})
.catch(error => {
console.error(error);
alert("An error occurred while submitting the data.");
});
});
</script>
</body>
</html>