|
| 1 | +<!DOCTYPE html> |
| 2 | +<html> |
| 3 | + |
| 4 | +<head> |
| 5 | + <meta charset="utf-8"> |
| 6 | + <title> |
| 7 | + the boxes based on a selection from a dropdown menu |
| 8 | + </title> |
| 9 | + |
| 10 | + <style> |
| 11 | + li { |
| 12 | + list-style: none; |
| 13 | + border: solid 1px black; |
| 14 | + height: 25px; |
| 15 | + width: 25px; |
| 16 | + border-radius: 100px; |
| 17 | + text-align: center; |
| 18 | + float: left; |
| 19 | + padding: 25px; |
| 20 | + margin: 5px; |
| 21 | + } |
| 22 | + </style> |
| 23 | +</head> |
| 24 | + |
| 25 | +<body> |
| 26 | + |
| 27 | + <label>Select Color:</label> |
| 28 | + <select id="color_select" onchange="changeColor()"> |
| 29 | + <option value="red">Red</option> |
| 30 | + <option value="green">Green</option> |
| 31 | + <option value="blue">Blue</option> |
| 32 | + <option value="yellow">Yellow</option> |
| 33 | + <option value="purple">Purple</option> |
| 34 | + </select> |
| 35 | + |
| 36 | + <label>Enter Number:</label> |
| 37 | + <input type="text" id="box_no"> |
| 38 | + <button onclick="changeColor()">Result</button> |
| 39 | + |
| 40 | + <ul id="print"> |
| 41 | + </ul> |
| 42 | + |
| 43 | + <script type="text/javascript"> |
| 44 | + |
| 45 | + function generateNewColor() { |
| 46 | + const hexCharacters = '0123456789ABCDEF'; |
| 47 | + let hexColorRep = "#"; |
| 48 | + for (let i = 0; i < 6; i++) { |
| 49 | + hexColorRep += hexCharacters[Math.floor(Math.random() * 16)]; |
| 50 | + } |
| 51 | + return hexColorRep; |
| 52 | + } |
| 53 | + |
| 54 | + function changeColor() { |
| 55 | + let color = document.getElementById("color_select").value; |
| 56 | + let list = parseInt(document.getElementById("box_no").value); |
| 57 | + let print_data = document.getElementById("print"); |
| 58 | + print_data.innerHTML = ''; // Clear previous content |
| 59 | + for (let i = 0; i < list; i++) { |
| 60 | + let listItem = document.createElement('li'); |
| 61 | + listItem.style.backgroundColor = color; |
| 62 | + listItem.textContent = i + 1; |
| 63 | + print_data.appendChild(listItem); |
| 64 | + } |
| 65 | + } |
| 66 | + </script> |
| 67 | + |
| 68 | +</body> |
| 69 | + |
| 70 | +</html> |
0 commit comments