Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

237
Vistas
How to get a value from color picker in Javascript and use the color value later

When the user chose a colour in the colour picker. How can I get the colour value and use the colour value later in the code?

<!DOCTYPE HTML>
<HTML>

<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title></title>
</head>
<body>
<label for="color">Please chose a color </label>
<input type="color" id="color" name="color2">
  
 <script>
        let userColor= document.querySelector("#color").value
        console.log(userColor)
 </script>
 </body>
</html>
about 4 years ago · Juan Pablo Isaza
3 Respuestas
Responde la pregunta

0

Get the value with onchange event:

document.querySelector("#color").onchange = e => {
   console.log(e.target.value)
}
<label for="color">Please chose a color </label>
<input type="color" id="color" name="color2">

about 4 years ago · Juan Pablo Isaza Denunciar

0

You Should add a change event listener to color input like this

<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title></title>
</head>
<body>
<label for="color">Please chose a color </label>
<input type="color" id="color" name="color2">

 <script>
        let userColor= document.querySelector("#color");
   
   userColor.addEventListener("change",(e) => {
          console.log(e.target.value)
   })
        
 </script>
 </body>
</html>
about 4 years ago · Juan Pablo Isaza Denunciar

0

You need to use addEventListener, so then you can call to one function every time this cganges:

<body>
<label for="color">Please chose a color </label>
<input type="color" id="color" name="color2">
<button onclick="whatColor()">ASDASD</button>

<script>
    let color = "";
    let userColor = document.querySelector("#color");
    userColor.addEventListener("change", myFunction);
    function myFunction() {
        console.log(userColor.value);
        color = userColor.value;
    }
    function whatColor() {
        console.log(color);
    }
</script>
</body>

This will call myFunction every time your input value changes. For making this write something, you will need to change the color, for make sure you change color, you should click outside the input when you choose your color.

You can also use userColor.addEventListener("input", myFunction); who will print every time you click on input

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda