i've been using FabricJS for a couple days now, and i'm having trouble grabbing the value of my dropdown menu so I can properly apply the desired shape with an eventlistener of "click. So when I hit the dropdown menu and select "rectangle" and hit the button, it should generate a rectangle. Here is my code:
HTML:
<p>Choose a Shape</p>
<select id="shapesId">
<option value="square">Square</option>
<option value="rectangle">Rectangle</option>
<option value="triangle">Triangle</option>
<option value="circle">Circle</option>
<option value="polygon">Polygon</option>
<option value="ellipse">Ellipse</option>
<option value="line">Line</option>
</select>
<button id="realShapes">Go!</button>
so when we hit "Go!" I want to get the value of whatever is selected through the option of shapes. And now here is my Javascript:
const shapes = document.getElementById("shapesId");
const e = shapes.value;
const clickShapes = document.getElementById("realShapes");
clickShapes.addEventListener("click", () => {
if(e === "Rectangle") {
const rect = new fabric.Rect({
left: 100,
top: 100,
fill: 'black',
width: 70,
height: 70,
angle: 45
});
canvas.add(rect);
}
canvas.renderAll();
})
I am so lost right now,and been trying to figure this out for hours, any help would be appreciated. Thank you to whoever is reading this!