I need to populate a dropdown list with an array of color names. Below is the HTML and js codes I have, but when I actually press the drop-down, none of the colors show up and when I click the colors, the color of the canvas does not change. It also needs to have a button that clears the canvas when pressed. HTML
<!DOCTYPE html>
<html lang="en">
<head>
<title>Project 3</title>
<meta charset="utf-8">
<meta name="description" content="Project 3">
<meta name="author" content="Kim Peoples">
<link rel="stylesheet" href="p3.css">
<script src="p3.js"> </script>
</head>
<body>
<canvas width="500" height="500" id="myCanvas"></canvas>
<form id="myForm">
<select id="colorDropdown">
<option>Select a Background Color</option>
</select>
</form>
<button onclick="clearCanvas">Clear Canvas</button>
</body>
</html>
JavaScript :
let selectElement = document.getElementById('#colorDropdown'),
let options = ["BlueViolet", "Crimson", "DarkSalmon", "OliveDrab", "SaddleBrown"];
for (let i < options.length - 1; i = 0; i++) {
let opt = options[i];
let optionList = document.createElement("option");
optionList.textContent = opt;
optionList.value = opt;
select.appendChild(optionList)
}
document.getElementById('colorDropdown').onchange = function(){
let c = document.getElementById("myCanvas");
let ctx = c.getContext("2d");
ctx.beginPath();
ctx.rect(20, 20, 150, 100);
ctx.fillStyle = document.getElementById('colorDropdown').value;
ctx.fill();
};