Reputation: 3
I'm trying to return the color code from a color-picker with this code but just can't make it work:
<!DOCTYPE html>
<html>
<body bgcolor="2F2F2F">
<input type="color" id="color">
<script>
document.getElementById("color").onchange = function TestOnTextChange() {
return this.value;
}
</script>
<input type="text" id="myTextBox" onchange="TestOnTextChange()">
</body>
</html>
Upvotes: 0
Views: 39
Reputation: 1086
You missed on setting the value of text input with the color code;
<!DOCTYPE html>
<html>
<body bgcolor="2F2F2F">
<input type="color" id="color">
<script>
document.getElementById("color").onchange = function TestOnTextChange() {
document.getElementById("myTextBox").value = this.value;
}
</script>
<input type="text" id="myTextBox" onchange="TestOnTextChange()">
</body>
</html>
Upvotes: 1