Skip to content

HTML5 input type Color read single RGB values

With this code on browser many field are available by the user, it can change R,G,B, HEX VALUE, HUE ecc. I need to read only the Red value.

  <input id="color_pick"type="color" value="#ff0000">

var toread = document.getElementById('color_pick');
toread.value # get the hex # would it be possible to get r?

I’ve read this document but cannot figure how to get the single R value from the input.



Since you already have hexadecimal from node.value property, you just have to convert it to integer.

function pickRedInt(){
  var toread = document.getElementById('color_pick');
  console.log("Red Value - "+parseInt("0x"+toread.value.slice(1,3)));

Try changing this:
<input id="color_pick"type="color" value="#ff0000" onchange="pickRedInt()">
7 People found this is helpful