forked from Pankaj-Str/JavaScript-Tutorial
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathselect_box_color.html
More file actions
70 lines (59 loc) · 1.52 KB
/
select_box_color.html
File metadata and controls
70 lines (59 loc) · 1.52 KB
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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>
the boxes based on a selection from a dropdown menu
</title>
<style>
li {
list-style: none;
border: solid 1px black;
height: 25px;
width: 25px;
border-radius: 100px;
text-align: center;
float: left;
padding: 25px;
margin: 5px;
}
</style>
</head>
<body>
<label>Select Color:</label>
<select id="color_select" onchange="changeColor()">
<option value="red">Red</option>
<option value="green">Green</option>
<option value="blue">Blue</option>
<option value="yellow">Yellow</option>
<option value="purple">Purple</option>
</select>
<label>Enter Number:</label>
<input type="text" id="box_no">
<button onclick="changeColor()">Result</button>
<ul id="print">
</ul>
<script type="text/javascript">
function generateNewColor() {
const hexCharacters = '0123456789ABCDEF';
let hexColorRep = "#";
for (let i = 0; i < 6; i++) {
hexColorRep += hexCharacters[Math.floor(Math.random() * 16)];
}
return hexColorRep;
}
function changeColor() {
let color = document.getElementById("color_select").value;
let list = parseInt(document.getElementById("box_no").value);
let print_data = document.getElementById("print");
print_data.innerHTML = ''; // Clear previous content
for (let i = 0; i < list; i++) {
let listItem = document.createElement('li');
listItem.style.backgroundColor = color;
listItem.textContent = i + 1;
print_data.appendChild(listItem);
}
}
</script>
</body>
</html>