forked from FaZeDrug/CSE-110-LAB-2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
108 lines (86 loc) · 3.28 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
102
103
104
105
106
107
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Form with JavaScript Inputs</title>
<style>
body {
font-family: Arial, sans-serif;
margin: 20px;
}
.container {
max-width: 400px;
margin: 0 auto;
}
label,
input {
display: block;
margin-bottom: 10px;
}
button {
margin-top: 10px;
}
.result {
margin-top: 20px;
}
</style>
</head>
<body>
<div class="container">
<h2>Create Your Sticky Note!</h2>
<form id="userForm">
<label for="title">Title:</label>
<input type="text" id="title" name="title" required>
<label for="content">Content:</label>
<input type="text" id="content" name="content" required>
<label for="label">Label Your Note:</label>
<select name="dropdown" id="notelabels">
<option value="personal">Personal</option>
<option value="dog">Dog</option>
<option value="cat">Cat</option>
<option value="hamster">Hamster</option>
<option value="parrot">Parrot</option>
<option value="spider">Spider</option>
<option value="goldfish">Goldfish</option>
</select>
<br> <!-- this is a line break (needed b/c if u comment it out, the submit button goes next to the dropdown) -->
<button type="submit">Submit</button>
</form>
<div class="result" id="result"></div>
</div>
<script>
document.getElementById("userForm").addEventListener("submit", function (event) {
event.preventDefault();
// Get the input values
const title = document.getElementById("title").value;
const content = document.getElementById("content").value;
const label = document.getElementById("notelabels").value;
// Alert warning if user exceeds 50 chars
if (title.length > 50){
alert("Title cannot exceed 50 characters.");
return;
}
// Display the result
const resultDiv = document.getElementById("result");
resultDiv.innerHTML = `<h3>Submitted Information</h3>
<p>Title: ${title}</p>
<p>Content: ${content}</p>
<p>Label: ${label}</p>`;
});
// Changes the background color of the input element onFocus
document.getElementById("title").addEventListener("focus", function () {
this.style.backgroundColor = "#e0f7fa"; // Light blue background on focus
});
document.getElementById("title").addEventListener("blur", function () {
this.style.backgroundColor = ""; // Reset background on blur
});
document.getElementById("content").addEventListener("focus", function () {
this.style.backgroundColor = "#e0f7fa"; // Light blue background on focus
});
document.getElementById("content").addEventListener("blur", function () {
this.style.backgroundColor = ""; // Reset background on blur
});
</script>
</body>
</html>