Search code examples
jqueryhexcolor-picker

JQuery color picker change hex value


I'm using this colorpicker http://www.eyecon.ro/colorpicker and am trying to capture the hex value so that I can use it on the server side to store the selected color.

I'm unable to get the selected color after changing the default color.

Here is my code:

 var currentHex = '#0000ff';
            alert(currentHex);
            $('#colorSelector').ColorPicker({
                color: currentHex,
                onShow: function (colpkr) {
                    $(colpkr).fadeIn(500);
                    return false;
                },
                onHide: function (colpkr) {
                    $(colpkr).fadeOut(500);
                    return false;
                },
                onChange: function (hsb, hex, rgb) {
                    // every time a new colour is selected, this function is called
                    currentHex = hex;
                    $('#mycolor').val = currentHex;
                }
            });

Html:

<div id="colorSelector"><div style="background-color: rgb(62, 62, 189); "></div></div>
<input type="text" maxlength="6" size="6" id="mycolor" value="00ff00">

Here is my Demo


Solution

  • $('#mycolor').val = currentHex; //wrong syntax
    

    should be

    $('#mycolor').val(currentHex);
    

    Updated Demo