Hello as I'm finding ways to create and editable Vinyl or text editor I cant make it work, I want an output similar to this link https://www.stickermule.com/products/vinyl-lettering , I made one but with buttons and it worked but I want to apply it via combo box but it wouldn't work, can someone help me? I'm using HTML CSS and JavaScript.
Here is the code i have tried
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<style>
.container {
display: flex;
align-items: center;
justify-content: center;
flex-direction: column;
}
p {
width: 40%;
border: 1px solid black;
padding: 10px;
font-weight: bold;
font-size: 18px;
}
button {
padding: 10px 20px;
margin: 5px;
}
</style>
</head>
<body>
<div class="container">
Select Color:
<select>
<option>Choose a Color</option>
<option id="btnRed">Red</option>
<option id="btnBlue">Blue</option>
<option id="btnGreen">Green</option>
</select>
<textarea style="width: 25%; height: 200px;"></textarea>
</div>
<script>
let btnRed = document.querySelector('#btnRed');
let btnBlue = document.querySelector('#btnBlue');
let btnGreen = document.querySelector('#btnGreen');
let content = document.querySelector('textarea');
btnRed.addEventListener('click',() => content.style.color = 'red');
btnBlue.addEventListener('click',() => content.style.color = 'blue');
btnGreen.addEventListener('click',() => content.style.color = 'green');
</script>
</body>
</html>
I developed this solution using jQuery for simplicity. When the change event of the <select> element is triggered, the value of the <option> elements is assigned to the <textarea> element whose id attribute is resultTextArea.
$( ".target" ).change(function() {
$('#resultTextArea').css('color', this.value);
});
.container {
display: flex;
align-items: center;
justify-content: center;
flex-direction: column;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="container">
Select Color:
<select class="target">
<option>Choose a Color</option>
<option id="btnRed" value="red">Red</option>
<option id="btnBlue" value="blue">Blue</option>
<option id="btnGreen" value="green">Green</option>
</select>
<textarea id="resultTextArea" style="width: 25%; height: 200px;"></textarea>
</div>
I have developed a solution using plain JavaScript in the solution below. The SetColor() method is called when the <select> element's onchange event is triggered; the value of the selected element in the <select> element is assigned to the color style of the <textarea> element.
function SetColor()
{
var value = document.getElementById("selectElement").value;
var textareaElement = document.getElementById("resultTextArea");
textareaElement.style.color = value;
}
.container {
display: flex;
align-items: center;
justify-content: center;
flex-direction: column;
}
<div class="container">
Select Color:
<select id="selectElement" onchange="SetColor()">
<option>Choose a Color</option>
<option id="btnRed" value="red">Red</option>
<option id="btnBlue" value="blue">Blue</option>
<option id="btnGreen" value="green">Green</option>
</select>
<textarea id="resultTextArea" style="width: 25%; height: 200px;"></textarea>