Patrik Frisk
Patrik Frisk

Reputation: 3

Im trying to get the color code from color picker

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

Answers (1)

Monica Acha
Monica Acha

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

Related Questions